Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,21 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
iface = gr.Interface(fn=do_action, inputs="text", outputs="text")
|
| 14 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from openai import OpenAI
|
| 3 |
|
| 4 |
+
# Initialize OpenAI moderation client
|
| 5 |
+
client = OpenAI()
|
| 6 |
|
| 7 |
+
def moderate_text(text):
|
| 8 |
+
response = client.moderations.create(
|
| 9 |
+
model="omni-moderation-latest",
|
| 10 |
+
input=text
|
| 11 |
+
)
|
| 12 |
+
moderation_categories = response["results"][0]["categories"]
|
| 13 |
+
moderation_flagged = response["results"][0]["flagged"]
|
| 14 |
+
if moderation_flagged:
|
| 15 |
+
flagged_categories = [category for category, flagged in moderation_categories.items() if flagged]
|
| 16 |
+
return f"The text is flagged for moderation due to: {', '.join(flagged_categories)}"
|
| 17 |
+
else:
|
| 18 |
+
return "The text is not flagged for any moderation issues."
|
| 19 |
|
| 20 |
+
iface = gr.Interface(fn=moderate_text, inputs="text", outputs="text")
|
|
|
|
|
|
|
| 21 |
iface.launch()
|