Spaces:
Sleeping
Sleeping
karwanjiru
commited on
Commit
•
656a88a
1
Parent(s):
473c5fd
debugging
Browse files
app.py
CHANGED
@@ -1,5 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
|
|
|
|
|
|
3 |
|
4 |
# Initialize the client
|
5 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
@@ -48,13 +51,30 @@ def moderate_post(post):
|
|
48 |
|
49 |
# Define the function to generate images
|
50 |
def generate_image(prompt):
|
|
|
51 |
response = client.text_to_image(prompt)
|
52 |
-
|
|
|
53 |
|
54 |
# Define the function to moderate images
|
55 |
def moderate_image(image):
|
56 |
-
#
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
# Create the Gradio interface
|
60 |
demo = gr.Blocks()
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
+
import requests
|
4 |
+
from PIL import Image
|
5 |
+
from io import BytesIO
|
6 |
|
7 |
# Initialize the client
|
8 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
|
|
51 |
|
52 |
# Define the function to generate images
|
53 |
def generate_image(prompt):
|
54 |
+
# Replace with actual model or API endpoint for image generation
|
55 |
response = client.text_to_image(prompt)
|
56 |
+
image = Image.open(BytesIO(response))
|
57 |
+
return image
|
58 |
|
59 |
# Define the function to moderate images
|
60 |
def moderate_image(image):
|
61 |
+
# Convert the PIL image to a format that can be sent for moderation
|
62 |
+
buffered = BytesIO()
|
63 |
+
image.save(buffered, format="JPEG")
|
64 |
+
image_bytes = buffered.getvalue()
|
65 |
+
|
66 |
+
# Placeholder URL for an image moderation API
|
67 |
+
moderation_api_url = "https://example.com/moderation/api"
|
68 |
+
|
69 |
+
# Send the image to the moderation API
|
70 |
+
response = requests.post(moderation_api_url, files={"file": image_bytes})
|
71 |
+
result = response.json()
|
72 |
+
|
73 |
+
# Check the result from the moderation API
|
74 |
+
if result.get("moderation_status") == "approved":
|
75 |
+
return "Image adheres to community guidelines."
|
76 |
+
else:
|
77 |
+
return "Image does not adhere to community guidelines."
|
78 |
|
79 |
# Create the Gradio interface
|
80 |
demo = gr.Blocks()
|