Spaces:
Runtime error
Runtime error
File size: 1,035 Bytes
1352a28 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
import os
# import json
import requests
from dotenv import load_dotenv
load_dotenv()
def moderate_image(image_url):
"""
Process an image by moderating it and extracting a caption if not moderated.
Args:
- image_url (str): URL of the image to be processed.
Returns:
- str: If the image is moderated, returns "moderated".
If not moderated, returns the extracted caption.
"""
mc_key = os.getenv('MODERATE_CONTENT_KEY')
payload = {
'key': mc_key,
'url': image_url
}
endpoint = 'https://api.moderatecontent.com/moderate/'
response = requests.post(endpoint, data=payload)
if response.status_code == 200:
response_json = response.json()
return response_json['rating_index']
else:
print(response.status_code)
return None
# Example usage
# url = "https://www.rainforest-alliance.org/wp-content/uploads/2021/06/capybara-square-1-400x400.jpg.webp"
# result = moderate_image(url)
# print(result)
|