Spaces:
Sleeping
Sleeping
Update app.py
Browse files27 unmodified lines28293031323334353637382 unmodified lines41424344454647484950515253545556575859606162636465667 unmodified lines74757677787980816 unmodified lines8889909192936 unmodified lines10010110210310410510610710810911011127 unmodified linesif not text.strip():return "Please enter some text to analyze.", ""# Map strings from UI to Enumsmode = ReasoningMode(mode_str.lower())fmt = OutputFormat(format_str.lower())# Generateresult = generate_moderation(model,prompt=text,2 unmodified lines)verdict_output = result["verdict_fmt"]# If JSON format is selected, prettify it for the textboxif fmt == OutputFormat.JSON:verdict_output = json.dumps(verdict_output, indent=2)thinking_process = result.get("thinking", "No reasoning generated.")return verdict_output, thinking_process# 2. Build Gradio UItheme = gr.themes.Soft(primary_hue="orange",secondary_hue="gray",)with gr.Blocks(theme=theme, title="GreesyGPT Content Moderation") as demo:gr.Markdown("# 🛡️ GreesyGPT Content Moderation")gr.Markdown("A reasoning-based safety model that analyzes content for violations ""using chain-of-thought deliberation.")with gr.Row():with gr.Column(scale=2):7 unmodified linesmode_dropdown = gr.Dropdown(choices=[m.value for m in ReasoningMode],value="low",label="Reasoning Mode",info="Higher modes are more thorough but slower.")format_dropdown = gr.Dropdown(choices=[f.value for f in OutputFormat],6 unmodified lineswith gr.Column(scale=3):output_verdict = gr.Markdown(label="Verdict")with gr.Accordion("View Internal Reasoning (Thinking Process)", open=False):output_thinking = gr.Textbox(label="Chain of Thought",6 unmodified lines["You're so stupid, nobody likes you.", "medium", "markdown"],["How do I fix a bug in my Python code?", "none", "markdown"],["CONGRATULATIONS! You won a $1000 gift card! Click here!", "low", "json"],["I feel really hopeless and don't want to continue.", "high", "markdown"],],inputs=[input_text, mode_dropdown, format_dropdown])with gr.Expander("System Information"):gr.Code(describe_reasoning_modes(), language="text")submit_btn.click(27 unmodified lines2829303132333435362 unmodified lines394041424344454647484950515253545556577 unmodified lines656667686970716 unmodified lines787980818283846 unmodified lines91929394959697989910010110227 unmodified linesif not text.strip():return "Please enter some text to analyze.", ""mode = ReasoningMode(mode_str.lower())fmt = OutputFormat(format_str.lower())result = generate_moderation(model,prompt=text,2 unmodified lines)verdict_output = result["verdict_fmt"]if fmt == OutputFormat.JSON:verdict_output = f"```json\n{json.dumps(verdict_output, indent=2)}\n```"thinking_process = result.get("thinking", "No reasoning generated.")return verdict_output, thinking_process# 2. Build Gradio UItheme = gr.themes.Soft(primary_hue="orange", secondary_hue="gray")with gr.Blocks(theme=theme, title="GreesyGPT Content Moderation") as demo:gr.Markdown("# 🛡️ GreesyGPT Content Moderation")gr.Markdown("Reasoning-based safety model using chain-of-thought deliberation.")with gr.Row():with gr.Column(scale=2):7 unmodified linesmode_dropdown = gr.Dropdown(choices=[m.value for m in ReasoningMode],value="low",label="Reasoning Mode")format_dropdown = gr.Dropdown(choices=[f.value for f in OutputFormat],6 unmodified lineswith gr.Column(scale=3):output_verdict = gr.Markdown(label="Verdict")# FIXED: Changed Expander to Accordionwith gr.Accordion("View Internal Reasoning (Thinking Process)", open=False):output_thinking = gr.Textbox(label="Chain of Thought",6 unmodified lines["You're so stupid, nobody likes you.", "medium", "markdown"],["How do I fix a bug in my Python code?", "none", "markdown"],["CONGRATULATIONS! You won a $1000 gift card! Click here!", "low", "json"],],inputs=[input_text, mode_dropdown, format_dropdown])# FIXED: Changed Expander to Accordionwith gr.Accordion("System Information / Reasoning Mode Definitions", open=False):gr.Code(describe_reasoning_modes(), language="text")submit_btn.click(
app.py+7-16