"""Gradio UI for the DSPy text agent.""" import dspy import gradio as gr from text_agent import TextAgent # Configure on import lm = dspy.LM( "nvidia_nim/nvidia/nemotron-3-super-120b-a12b", max_tokens=4096, ) dspy.configure(lm=lm) agent = TextAgent() def draft_message(context, channel, tone): """Draft a message via the text agent.""" if not context.strip(): return "", "" result = agent.draft( context=context, channel=channel, tone=tone, ) if channel == "email": return result["subject"], result["body"] return "", result["message"] def analyze_tone(text): """Analyze tone of input text.""" if not text.strip(): return "" return agent.analyze_tone(text) with gr.Blocks() as demo: gr.Markdown( "# DSPy Text Agent\n" "Draft emails and Teams messages powered by " "**Nemotron 3 Super** + MIPRO-optimized prompts." ) with gr.Tab("Draft"): with gr.Row(): with gr.Column(): context_in = gr.Textbox( label="Context", placeholder="What should the " "message be about?", lines=3, ) channel_in = gr.Radio( ["email", "teams"], label="Channel", value="email", ) tone_in = gr.Dropdown( [ "professional", "casual", "friendly", "formal", "urgent", ], label="Tone", value="professional", ) draft_btn = gr.Button( "Draft", variant="primary", ) with gr.Column(): subject_out = gr.Textbox( label="Subject", interactive=True, ) body_out = gr.Textbox( label="Body / Message", lines=12, interactive=True, ) draft_btn.click( fn=draft_message, inputs=[context_in, channel_in, tone_in], outputs=[subject_out, body_out], ) with gr.Tab("Tone Analyzer"): with gr.Row(): with gr.Column(): tone_text_in = gr.Textbox( label="Text to analyze", placeholder="Paste any text here...", lines=4, ) tone_btn = gr.Button( "Analyze Tone", variant="primary", ) with gr.Column(): tone_out = gr.Textbox( label="Detected Tone", interactive=True, ) tone_btn.click( fn=analyze_tone, inputs=[tone_text_in], outputs=[tone_out], ) gr.Markdown( "*Model: NVIDIA Nemotron 3 Super " "(120B/12B MoE) via NVIDIA NIM*" ) if __name__ == "__main__": demo.launch( theme=gr.themes.Soft( primary_hue="blue", neutral_hue="slate", ), )