ejarbe commited on
Commit
2c0467c
·
verified ·
1 Parent(s): fb64f4b

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +124 -0
app.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Gradio UI for the DSPy text agent."""
2
+
3
+ import dspy
4
+ import gradio as gr
5
+
6
+ from text_agent import TextAgent
7
+
8
+ # Configure on import
9
+ lm = dspy.LM(
10
+ "nvidia_nim/nvidia/nemotron-3-super-120b-a12b",
11
+ max_tokens=4096,
12
+ )
13
+ dspy.configure(lm=lm)
14
+ agent = TextAgent()
15
+
16
+
17
+ def draft_message(context, channel, tone):
18
+ """Draft a message via the text agent."""
19
+ if not context.strip():
20
+ return "", ""
21
+ result = agent.draft(
22
+ context=context,
23
+ channel=channel,
24
+ tone=tone,
25
+ )
26
+ if channel == "email":
27
+ return result["subject"], result["body"]
28
+ return "", result["message"]
29
+
30
+
31
+ def analyze_tone(text):
32
+ """Analyze tone of input text."""
33
+ if not text.strip():
34
+ return ""
35
+ return agent.analyze_tone(text)
36
+
37
+
38
+ with gr.Blocks() as demo:
39
+ gr.Markdown(
40
+ "# DSPy Text Agent\n"
41
+ "Draft emails and Teams messages powered by "
42
+ "**Nemotron 3 Super** + MIPRO-optimized prompts."
43
+ )
44
+
45
+ with gr.Tab("Draft"):
46
+ with gr.Row():
47
+ with gr.Column():
48
+ context_in = gr.Textbox(
49
+ label="Context",
50
+ placeholder="What should the "
51
+ "message be about?",
52
+ lines=3,
53
+ )
54
+ channel_in = gr.Radio(
55
+ ["email", "teams"],
56
+ label="Channel",
57
+ value="email",
58
+ )
59
+ tone_in = gr.Dropdown(
60
+ [
61
+ "professional",
62
+ "casual",
63
+ "friendly",
64
+ "formal",
65
+ "urgent",
66
+ ],
67
+ label="Tone",
68
+ value="professional",
69
+ )
70
+ draft_btn = gr.Button(
71
+ "Draft",
72
+ variant="primary",
73
+ )
74
+ with gr.Column():
75
+ subject_out = gr.Textbox(
76
+ label="Subject",
77
+ interactive=False,
78
+ )
79
+ body_out = gr.Textbox(
80
+ label="Body / Message",
81
+ lines=12,
82
+ interactive=False,
83
+ )
84
+ draft_btn.click(
85
+ fn=draft_message,
86
+ inputs=[context_in, channel_in, tone_in],
87
+ outputs=[subject_out, body_out],
88
+ )
89
+
90
+ with gr.Tab("Tone Analyzer"):
91
+ with gr.Row():
92
+ with gr.Column():
93
+ tone_text_in = gr.Textbox(
94
+ label="Text to analyze",
95
+ placeholder="Paste any text here...",
96
+ lines=4,
97
+ )
98
+ tone_btn = gr.Button(
99
+ "Analyze Tone",
100
+ variant="primary",
101
+ )
102
+ with gr.Column():
103
+ tone_out = gr.Textbox(
104
+ label="Detected Tone",
105
+ interactive=False,
106
+ )
107
+ tone_btn.click(
108
+ fn=analyze_tone,
109
+ inputs=[tone_text_in],
110
+ outputs=[tone_out],
111
+ )
112
+
113
+ gr.Markdown(
114
+ "*Model: NVIDIA Nemotron 3 Super "
115
+ "(120B/12B MoE) via NVIDIA NIM*"
116
+ )
117
+
118
+ if __name__ == "__main__":
119
+ demo.launch(
120
+ theme=gr.themes.Soft(
121
+ primary_hue="blue",
122
+ neutral_hue="slate",
123
+ ),
124
+ )