Spaces:
Sleeping
Sleeping
Update app.py
Browse files27 unmodified lines28293031313233353435362 unmodified lines39404144424643444546474849535455565051525360616263545556577 unmodified lines6566677778686970716 unmodified lines787980818283846 unmodified lines91929310394959697108989910010110227 unmodified lines if not text.strip(): return "Please enter some text to analyze.", ""
# Map strings from UI to Enums mode = ReasoningMode(mode_str.lower()) fmt = OutputFormat(format_str.lower())
# Generate result = generate_moderation( model, prompt=text, 2 unmodified lines )
verdict_output = result["verdict_fmt"] # If JSON format is selected, prettify it for the textbox if fmt == OutputFormat.JSON: verdict_output = json.dumps(verdict_output, indent=2) 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",)theme = 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." ) gr.Markdown("Reasoning-based safety model using chain-of-thought deliberation.") with gr.Row(): with gr.Column(scale=2):7 unmodified lines mode_dropdown = gr.Dropdown( choices=[m.value for m in ReasoningMode], value="low", label="Reasoning Mode", info="Higher modes are more thorough but slower." label="Reasoning Mode" ) format_dropdown = gr.Dropdown( choices=[f.value for f in OutputFormat],6 unmodified lines with gr.Column(scale=3): output_verdict = gr.Markdown(label="Verdict") # FIXED: Changed Expander to Accordion 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"): # FIXED: Changed Expander to Accordion with gr.Accordion("System Information / Reasoning Mode Definitions", open=False): gr.Code(describe_reasoning_modes(), language="text")
submit_btn.click(app.py+7-16