Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -43,29 +43,35 @@ def moderate_text(text, safer_value):
|
|
43 |
Returns:
|
44 |
tuple: A tuple containing the moderation result and the generated image.
|
45 |
"""
|
46 |
-
|
47 |
-
|
|
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
|
62 |
-
|
63 |
-
|
64 |
|
65 |
-
|
66 |
-
|
67 |
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
# Define the Gradio interface
|
71 |
demo = gr.Interface(
|
|
|
43 |
Returns:
|
44 |
tuple: A tuple containing the moderation result and the generated image.
|
45 |
"""
|
46 |
+
try:
|
47 |
+
# Fetch the dynamic endpoint
|
48 |
+
dynamic_endpoint = get_dynamic_endpoint()
|
49 |
|
50 |
+
# Initialize the client with the dynamic endpoint
|
51 |
+
client = Client(dynamic_endpoint, hf_token=HF_TOKEN)
|
52 |
+
result = client.predict(
|
53 |
+
text,
|
54 |
+
safer_value,
|
55 |
+
api_name="/censor_me"
|
56 |
+
)
|
57 |
|
58 |
+
# Ensure the result contains the expected data
|
59 |
+
base64_data = result.get('plot', '').split(',')[1] if 'plot' in result else None
|
60 |
+
if not base64_data:
|
61 |
+
raise ValueError("Expected plot data not found in the result.")
|
62 |
|
63 |
+
# Decode base64 to bytes
|
64 |
+
img_data = base64.b64decode(base64_data)
|
65 |
|
66 |
+
# Convert bytes to PIL Image
|
67 |
+
img = Image.open(io.BytesIO(img_data))
|
68 |
|
69 |
+
return result, img
|
70 |
+
|
71 |
+
except Exception as e:
|
72 |
+
# Log the error for debugging purposes
|
73 |
+
print(f"Error occurred: {e}")
|
74 |
+
return str(e), None
|
75 |
|
76 |
# Define the Gradio interface
|
77 |
demo = gr.Interface(
|