Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import openai
|
| 3 |
-
import os
|
| 4 |
|
| 5 |
-
openai.api_key =
|
| 6 |
|
| 7 |
def moderate_text(text):
|
| 8 |
text = str(text).strip() if text else ""
|
|
@@ -23,14 +22,16 @@ def moderate_text(text):
|
|
| 23 |
return f"The text is flagged for moderation due to: {', '.join(flagged_categories)}"
|
| 24 |
else:
|
| 25 |
return "The text is not flagged for any moderation issues."
|
| 26 |
-
except
|
| 27 |
-
return f"An error occurred: {
|
| 28 |
|
| 29 |
iface = gr.Interface(
|
| 30 |
fn=moderate_text,
|
| 31 |
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
|
| 32 |
outputs="text",
|
| 33 |
-
title="Text Moderation Tool"
|
|
|
|
| 34 |
)
|
| 35 |
|
| 36 |
-
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import openai
|
|
|
|
| 3 |
|
| 4 |
+
openai.api_key = "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"
|
| 5 |
|
| 6 |
def moderate_text(text):
|
| 7 |
text = str(text).strip() if text else ""
|
|
|
|
| 22 |
return f"The text is flagged for moderation due to: {', '.join(flagged_categories)}"
|
| 23 |
else:
|
| 24 |
return "The text is not flagged for any moderation issues."
|
| 25 |
+
except Exception as e:
|
| 26 |
+
return f"An error occurred: {e}"
|
| 27 |
|
| 28 |
iface = gr.Interface(
|
| 29 |
fn=moderate_text,
|
| 30 |
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
|
| 31 |
outputs="text",
|
| 32 |
+
title="Text Moderation Tool",
|
| 33 |
+
description="Paste some text, and this tool will use OpenAI's Moderation API to determine if it contains sensitive or flagged content."
|
| 34 |
)
|
| 35 |
|
| 36 |
+
if __name__ == "__main__":
|
| 37 |
+
iface.launch()
|