Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,11 +28,9 @@ def moderate(text, mode_str, format_str):
|
|
| 28 |
if not text.strip():
|
| 29 |
return "Please enter some text to analyze.", ""
|
| 30 |
|
| 31 |
-
# Map strings from UI to Enums
|
| 32 |
mode = ReasoningMode(mode_str.lower())
|
| 33 |
fmt = OutputFormat(format_str.lower())
|
| 34 |
|
| 35 |
-
# Generate
|
| 36 |
result = generate_moderation(
|
| 37 |
model,
|
| 38 |
prompt=text,
|
|
@@ -41,26 +39,19 @@ def moderate(text, mode_str, format_str):
|
|
| 41 |
)
|
| 42 |
|
| 43 |
verdict_output = result["verdict_fmt"]
|
| 44 |
-
# If JSON format is selected, prettify it for the textbox
|
| 45 |
if fmt == OutputFormat.JSON:
|
| 46 |
-
verdict_output = json.dumps(verdict_output, indent=2)
|
| 47 |
|
| 48 |
thinking_process = result.get("thinking", "No reasoning generated.")
|
| 49 |
|
| 50 |
return verdict_output, thinking_process
|
| 51 |
|
| 52 |
# 2. Build Gradio UI
|
| 53 |
-
theme = gr.themes.Soft(
|
| 54 |
-
primary_hue="orange",
|
| 55 |
-
secondary_hue="gray",
|
| 56 |
-
)
|
| 57 |
|
| 58 |
with gr.Blocks(theme=theme, title="GreesyGPT Content Moderation") as demo:
|
| 59 |
gr.Markdown("# 🛡️ GreesyGPT Content Moderation")
|
| 60 |
-
gr.Markdown(
|
| 61 |
-
"A reasoning-based safety model that analyzes content for violations "
|
| 62 |
-
"using chain-of-thought deliberation."
|
| 63 |
-
)
|
| 64 |
|
| 65 |
with gr.Row():
|
| 66 |
with gr.Column(scale=2):
|
|
@@ -74,8 +65,7 @@ with gr.Blocks(theme=theme, title="GreesyGPT Content Moderation") as demo:
|
|
| 74 |
mode_dropdown = gr.Dropdown(
|
| 75 |
choices=[m.value for m in ReasoningMode],
|
| 76 |
value="low",
|
| 77 |
-
label="Reasoning Mode"
|
| 78 |
-
info="Higher modes are more thorough but slower."
|
| 79 |
)
|
| 80 |
format_dropdown = gr.Dropdown(
|
| 81 |
choices=[f.value for f in OutputFormat],
|
|
@@ -88,6 +78,7 @@ with gr.Blocks(theme=theme, title="GreesyGPT Content Moderation") as demo:
|
|
| 88 |
with gr.Column(scale=3):
|
| 89 |
output_verdict = gr.Markdown(label="Verdict")
|
| 90 |
|
|
|
|
| 91 |
with gr.Accordion("View Internal Reasoning (Thinking Process)", open=False):
|
| 92 |
output_thinking = gr.Textbox(
|
| 93 |
label="Chain of Thought",
|
|
@@ -100,12 +91,12 @@ with gr.Blocks(theme=theme, title="GreesyGPT Content Moderation") as demo:
|
|
| 100 |
["You're so stupid, nobody likes you.", "medium", "markdown"],
|
| 101 |
["How do I fix a bug in my Python code?", "none", "markdown"],
|
| 102 |
["CONGRATULATIONS! You won a $1000 gift card! Click here!", "low", "json"],
|
| 103 |
-
["I feel really hopeless and don't want to continue.", "high", "markdown"],
|
| 104 |
],
|
| 105 |
inputs=[input_text, mode_dropdown, format_dropdown]
|
| 106 |
)
|
| 107 |
|
| 108 |
-
|
|
|
|
| 109 |
gr.Code(describe_reasoning_modes(), language="text")
|
| 110 |
|
| 111 |
submit_btn.click(
|
|
|
|
| 28 |
if not text.strip():
|
| 29 |
return "Please enter some text to analyze.", ""
|
| 30 |
|
|
|
|
| 31 |
mode = ReasoningMode(mode_str.lower())
|
| 32 |
fmt = OutputFormat(format_str.lower())
|
| 33 |
|
|
|
|
| 34 |
result = generate_moderation(
|
| 35 |
model,
|
| 36 |
prompt=text,
|
|
|
|
| 39 |
)
|
| 40 |
|
| 41 |
verdict_output = result["verdict_fmt"]
|
|
|
|
| 42 |
if fmt == OutputFormat.JSON:
|
| 43 |
+
verdict_output = f"```json\n{json.dumps(verdict_output, indent=2)}\n```"
|
| 44 |
|
| 45 |
thinking_process = result.get("thinking", "No reasoning generated.")
|
| 46 |
|
| 47 |
return verdict_output, thinking_process
|
| 48 |
|
| 49 |
# 2. Build Gradio UI
|
| 50 |
+
theme = gr.themes.Soft(primary_hue="orange", secondary_hue="gray")
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
with gr.Blocks(theme=theme, title="GreesyGPT Content Moderation") as demo:
|
| 53 |
gr.Markdown("# 🛡️ GreesyGPT Content Moderation")
|
| 54 |
+
gr.Markdown("Reasoning-based safety model using chain-of-thought deliberation.")
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
with gr.Row():
|
| 57 |
with gr.Column(scale=2):
|
|
|
|
| 65 |
mode_dropdown = gr.Dropdown(
|
| 66 |
choices=[m.value for m in ReasoningMode],
|
| 67 |
value="low",
|
| 68 |
+
label="Reasoning Mode"
|
|
|
|
| 69 |
)
|
| 70 |
format_dropdown = gr.Dropdown(
|
| 71 |
choices=[f.value for f in OutputFormat],
|
|
|
|
| 78 |
with gr.Column(scale=3):
|
| 79 |
output_verdict = gr.Markdown(label="Verdict")
|
| 80 |
|
| 81 |
+
# FIXED: Changed Expander to Accordion
|
| 82 |
with gr.Accordion("View Internal Reasoning (Thinking Process)", open=False):
|
| 83 |
output_thinking = gr.Textbox(
|
| 84 |
label="Chain of Thought",
|
|
|
|
| 91 |
["You're so stupid, nobody likes you.", "medium", "markdown"],
|
| 92 |
["How do I fix a bug in my Python code?", "none", "markdown"],
|
| 93 |
["CONGRATULATIONS! You won a $1000 gift card! Click here!", "low", "json"],
|
|
|
|
| 94 |
],
|
| 95 |
inputs=[input_text, mode_dropdown, format_dropdown]
|
| 96 |
)
|
| 97 |
|
| 98 |
+
# FIXED: Changed Expander to Accordion
|
| 99 |
+
with gr.Accordion("System Information / Reasoning Mode Definitions", open=False):
|
| 100 |
gr.Code(describe_reasoning_modes(), language="text")
|
| 101 |
|
| 102 |
submit_btn.click(
|