MusaR commited on
Commit
d27fbee
·
verified ·
1 Parent(s): 8f5f193

Update research_agent/agent.py

Browse files
Files changed (1) hide show
  1. research_agent/agent.py +5 -46
research_agent/agent.py CHANGED
@@ -7,6 +7,9 @@ from datetime import datetime
7
  import json
8
  import time
9
 
 
 
 
10
 
11
  google_key = os.getenv("GOOGLE_API_KEY")
12
  tavily_key = os.getenv("TAVILY_API_KEY")
@@ -17,22 +20,18 @@ if not google_key or not tavily_key:
17
  # Professional CSS with dark theme
18
  CSS = """
19
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono&display=swap');
20
-
21
  * {
22
  transition: all 0.3s ease;
23
  }
24
-
25
  body, .gradio-container {
26
  font-family: 'Inter', -apple-system, system-ui, sans-serif !important;
27
  background: #0a0a0a !important;
28
  color: #e4e4e7 !important;
29
  }
30
-
31
  .gradio-container {
32
  max-width: 1200px !important;
33
  margin: 0 auto !important;
34
  }
35
-
36
  /* Header */
37
  .header {
38
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%);
@@ -42,7 +41,6 @@ body, .gradio-container {
42
  text-align: center;
43
  box-shadow: 0 20px 40px rgba(0,0,0,0.5);
44
  }
45
-
46
  .header h1 {
47
  font-size: 3.5rem;
48
  font-weight: 800;
@@ -52,14 +50,12 @@ body, .gradio-container {
52
  margin: 0;
53
  letter-spacing: -1px;
54
  }
55
-
56
  .header p {
57
  color: #a5b4fc;
58
  font-size: 1.25rem;
59
  margin-top: 0.5rem;
60
  font-weight: 300;
61
  }
62
-
63
  /* Status Bar */
64
  .status-bar {
65
  background: #18181b;
@@ -71,13 +67,11 @@ body, .gradio-container {
71
  justify-content: space-between;
72
  align-items: center;
73
  }
74
-
75
  .status-indicator {
76
  display: flex;
77
  align-items: center;
78
  gap: 0.75rem;
79
  }
80
-
81
  .pulse-dot {
82
  width: 10px;
83
  height: 10px;
@@ -86,7 +80,6 @@ body, .gradio-container {
86
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 1);
87
  animation: pulse-animation 2s infinite;
88
  }
89
-
90
  @keyframes pulse-animation {
91
  0% {
92
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
@@ -98,7 +91,6 @@ body, .gradio-container {
98
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
99
  }
100
  }
101
-
102
  /* Chat Interface */
103
  #chatbot {
104
  background: #18181b !important;
@@ -106,11 +98,9 @@ body, .gradio-container {
106
  border-radius: 20px !important;
107
  box-shadow: 0 10px 30px rgba(0,0,0,0.5) !important;
108
  }
109
-
110
  #chatbot .message-wrap {
111
  padding: 0 !important;
112
  }
113
-
114
  #chatbot .message {
115
  padding: 1.5rem !important;
116
  margin: 0.5rem !important;
@@ -118,35 +108,29 @@ body, .gradio-container {
118
  font-size: 1.05rem !important;
119
  line-height: 1.7 !important;
120
  }
121
-
122
  #chatbot .user {
123
  background: linear-gradient(135deg, #4c1d95 0%, #5b21b6 100%) !important;
124
  color: #f3f4f6 !important;
125
  margin-left: 20% !important;
126
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3) !important;
127
  }
128
-
129
  #chatbot .bot {
130
  background: #27272a !important;
131
  color: #e4e4e7 !important;
132
  margin-right: 20% !important;
133
  border: 1px solid #3f3f46 !important;
134
  }
135
-
136
  #chatbot .bot h1, #chatbot .bot h2, #chatbot .bot h3 {
137
  color: #a78bfa !important;
138
  margin-top: 1.5rem !important;
139
  margin-bottom: 1rem !important;
140
  }
141
-
142
  #chatbot .bot h1 { font-size: 2rem !important; }
143
  #chatbot .bot h2 { font-size: 1.5rem !important; }
144
  #chatbot .bot h3 { font-size: 1.25rem !important; }
145
-
146
  #chatbot .bot strong {
147
  color: #c4b5fd !important;
148
  }
149
-
150
  #chatbot .bot code {
151
  background: #374151 !important;
152
  color: #fbbf24 !important;
@@ -154,18 +138,15 @@ body, .gradio-container {
154
  border-radius: 4px !important;
155
  font-family: 'JetBrains Mono', monospace !important;
156
  }
157
-
158
  #chatbot .bot a {
159
  color: #60a5fa !important;
160
  text-decoration: none !important;
161
  border-bottom: 1px solid transparent !important;
162
  transition: border-color 0.2s !important;
163
  }
164
-
165
  #chatbot .bot a:hover {
166
  border-bottom-color: #60a5fa !important;
167
  }
168
-
169
  /* Progress Messages */
170
  .progress-message {
171
  background: #1e1b4b;
@@ -174,7 +155,6 @@ body, .gradio-container {
174
  margin: 1rem 0;
175
  border-radius: 0 8px 8px 0;
176
  }
177
-
178
  /* Input Area */
179
  .input-group {
180
  background: #18181b;
@@ -183,7 +163,6 @@ body, .gradio-container {
183
  padding: 1.5rem;
184
  margin-top: 2rem;
185
  }
186
-
187
  #user-input textarea {
188
  background: #27272a !important;
189
  border: 2px solid #3f3f46 !important;
@@ -193,13 +172,11 @@ body, .gradio-container {
193
  font-size: 1.05rem !important;
194
  min-height: 80px !important;
195
  }
196
-
197
  #user-input textarea:focus {
198
  border-color: #6366f1 !important;
199
  outline: none !important;
200
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1) !important;
201
  }
202
-
203
  /* Buttons */
204
  .submit-btn {
205
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%) !important;
@@ -212,16 +189,13 @@ body, .gradio-container {
212
  cursor: pointer !important;
213
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4) !important;
214
  }
215
-
216
  .submit-btn:hover {
217
  transform: translateY(-2px) !important;
218
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5) !important;
219
  }
220
-
221
  .submit-btn:active {
222
  transform: translateY(0) !important;
223
  }
224
-
225
  /* Examples */
226
  .examples-container {
227
  background: #18181b;
@@ -230,20 +204,17 @@ body, .gradio-container {
230
  padding: 1.5rem;
231
  margin-top: 2rem;
232
  }
233
-
234
  .examples-container h3 {
235
  color: #a78bfa;
236
  margin-bottom: 1rem;
237
  font-size: 1.25rem;
238
  font-weight: 600;
239
  }
240
-
241
  .examples-grid {
242
  display: grid;
243
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
244
  gap: 1rem;
245
  }
246
-
247
  .example-card {
248
  background: #27272a;
249
  border: 1px solid #3f3f46;
@@ -252,20 +223,17 @@ body, .gradio-container {
252
  cursor: pointer;
253
  transition: all 0.2s;
254
  }
255
-
256
  .example-card:hover {
257
  background: #374151;
258
  border-color: #6366f1;
259
  transform: translateY(-2px);
260
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
261
  }
262
-
263
  /* Loading Animation */
264
  .loading-wave {
265
  display: inline-flex;
266
  gap: 4px;
267
  }
268
-
269
  .loading-wave span {
270
  width: 4px;
271
  height: 20px;
@@ -273,17 +241,14 @@ body, .gradio-container {
273
  border-radius: 2px;
274
  animation: wave 1.2s linear infinite;
275
  }
276
-
277
  .loading-wave span:nth-child(2) { animation-delay: -1.1s; }
278
  .loading-wave span:nth-child(3) { animation-delay: -1s; }
279
  .loading-wave span:nth-child(4) { animation-delay: -0.9s; }
280
  .loading-wave span:nth-child(5) { animation-delay: -0.8s; }
281
-
282
  @keyframes wave {
283
  0%, 40%, 100% { transform: scaleY(0.4); }
284
  20% { transform: scaleY(1); }
285
  }
286
-
287
  /* Report Sections */
288
  .report-section {
289
  background: #1e1b4b;
@@ -292,7 +257,6 @@ body, .gradio-container {
292
  padding: 1.5rem;
293
  margin: 1rem 0;
294
  }
295
-
296
  .source-badge {
297
  display: inline-block;
298
  background: #374151;
@@ -302,7 +266,6 @@ body, .gradio-container {
302
  font-size: 0.875rem;
303
  margin: 0.25rem;
304
  }
305
-
306
  /* Export Section */
307
  .export-section {
308
  background: #18181b;
@@ -312,14 +275,12 @@ body, .gradio-container {
312
  margin-top: 2rem;
313
  text-align: center;
314
  }
315
-
316
  .export-buttons {
317
  display: flex;
318
  gap: 1rem;
319
  justify-content: center;
320
  margin-top: 1.5rem;
321
  }
322
-
323
  .export-btn {
324
  background: #27272a !important;
325
  border: 1px solid #3f3f46 !important;
@@ -332,12 +293,10 @@ body, .gradio-container {
332
  align-items: center !important;
333
  gap: 0.5rem !important;
334
  }
335
-
336
  .export-btn:hover {
337
  background: #374151 !important;
338
  border-color: #6366f1 !important;
339
  }
340
-
341
  /* Responsive */
342
  @media (max-width: 768px) {
343
  .header h1 { font-size: 2.5rem; }
@@ -503,7 +462,7 @@ I'll help you create a comprehensive research report on this topic. To ensure I
503
  plan = research_and_plan(config, planner_model, tavily_client, topic_state, user_input)
504
 
505
  # Show plan
506
- sections_list = "\n".join([f" {i+1}. **{s.title}**" for i, s in enumerate(plan['sections'])])
507
  plan_display = f"""
508
  ## 🚀 Starting Deep Research Process
509
 
@@ -605,7 +564,7 @@ with gr.Blocks(css=CSS, theme=gr.themes.Base()) as app:
605
  <span style="font-weight: 500;">System Active</span>
606
  </div>
607
  <div style="display: flex; gap: 2rem; align-items: center;">
608
- <span style="color: #71717a;">Powered by Gemini Pro</span>
609
  <span style="color: #71717a;">Enhanced with Tavily Search</span>
610
  </div>
611
  </div>
 
7
  import json
8
  import time
9
 
10
+ # Import the research agent components
11
+ from research_agent.config import AgentConfig
12
+ from research_agent.agent import get_clarifying_questions, research_and_plan, write_report_stream
13
 
14
  google_key = os.getenv("GOOGLE_API_KEY")
15
  tavily_key = os.getenv("TAVILY_API_KEY")
 
20
  # Professional CSS with dark theme
21
  CSS = """
22
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono&display=swap');
 
23
  * {
24
  transition: all 0.3s ease;
25
  }
 
26
  body, .gradio-container {
27
  font-family: 'Inter', -apple-system, system-ui, sans-serif !important;
28
  background: #0a0a0a !important;
29
  color: #e4e4e7 !important;
30
  }
 
31
  .gradio-container {
32
  max-width: 1200px !important;
33
  margin: 0 auto !important;
34
  }
 
35
  /* Header */
36
  .header {
37
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%);
 
41
  text-align: center;
42
  box-shadow: 0 20px 40px rgba(0,0,0,0.5);
43
  }
 
44
  .header h1 {
45
  font-size: 3.5rem;
46
  font-weight: 800;
 
50
  margin: 0;
51
  letter-spacing: -1px;
52
  }
 
53
  .header p {
54
  color: #a5b4fc;
55
  font-size: 1.25rem;
56
  margin-top: 0.5rem;
57
  font-weight: 300;
58
  }
 
59
  /* Status Bar */
60
  .status-bar {
61
  background: #18181b;
 
67
  justify-content: space-between;
68
  align-items: center;
69
  }
 
70
  .status-indicator {
71
  display: flex;
72
  align-items: center;
73
  gap: 0.75rem;
74
  }
 
75
  .pulse-dot {
76
  width: 10px;
77
  height: 10px;
 
80
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 1);
81
  animation: pulse-animation 2s infinite;
82
  }
 
83
  @keyframes pulse-animation {
84
  0% {
85
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
 
91
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
92
  }
93
  }
 
94
  /* Chat Interface */
95
  #chatbot {
96
  background: #18181b !important;
 
98
  border-radius: 20px !important;
99
  box-shadow: 0 10px 30px rgba(0,0,0,0.5) !important;
100
  }
 
101
  #chatbot .message-wrap {
102
  padding: 0 !important;
103
  }
 
104
  #chatbot .message {
105
  padding: 1.5rem !important;
106
  margin: 0.5rem !important;
 
108
  font-size: 1.05rem !important;
109
  line-height: 1.7 !important;
110
  }
 
111
  #chatbot .user {
112
  background: linear-gradient(135deg, #4c1d95 0%, #5b21b6 100%) !important;
113
  color: #f3f4f6 !important;
114
  margin-left: 20% !important;
115
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3) !important;
116
  }
 
117
  #chatbot .bot {
118
  background: #27272a !important;
119
  color: #e4e4e7 !important;
120
  margin-right: 20% !important;
121
  border: 1px solid #3f3f46 !important;
122
  }
 
123
  #chatbot .bot h1, #chatbot .bot h2, #chatbot .bot h3 {
124
  color: #a78bfa !important;
125
  margin-top: 1.5rem !important;
126
  margin-bottom: 1rem !important;
127
  }
 
128
  #chatbot .bot h1 { font-size: 2rem !important; }
129
  #chatbot .bot h2 { font-size: 1.5rem !important; }
130
  #chatbot .bot h3 { font-size: 1.25rem !important; }
 
131
  #chatbot .bot strong {
132
  color: #c4b5fd !important;
133
  }
 
134
  #chatbot .bot code {
135
  background: #374151 !important;
136
  color: #fbbf24 !important;
 
138
  border-radius: 4px !important;
139
  font-family: 'JetBrains Mono', monospace !important;
140
  }
 
141
  #chatbot .bot a {
142
  color: #60a5fa !important;
143
  text-decoration: none !important;
144
  border-bottom: 1px solid transparent !important;
145
  transition: border-color 0.2s !important;
146
  }
 
147
  #chatbot .bot a:hover {
148
  border-bottom-color: #60a5fa !important;
149
  }
 
150
  /* Progress Messages */
151
  .progress-message {
152
  background: #1e1b4b;
 
155
  margin: 1rem 0;
156
  border-radius: 0 8px 8px 0;
157
  }
 
158
  /* Input Area */
159
  .input-group {
160
  background: #18181b;
 
163
  padding: 1.5rem;
164
  margin-top: 2rem;
165
  }
 
166
  #user-input textarea {
167
  background: #27272a !important;
168
  border: 2px solid #3f3f46 !important;
 
172
  font-size: 1.05rem !important;
173
  min-height: 80px !important;
174
  }
 
175
  #user-input textarea:focus {
176
  border-color: #6366f1 !important;
177
  outline: none !important;
178
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1) !important;
179
  }
 
180
  /* Buttons */
181
  .submit-btn {
182
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%) !important;
 
189
  cursor: pointer !important;
190
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4) !important;
191
  }
 
192
  .submit-btn:hover {
193
  transform: translateY(-2px) !important;
194
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5) !important;
195
  }
 
196
  .submit-btn:active {
197
  transform: translateY(0) !important;
198
  }
 
199
  /* Examples */
200
  .examples-container {
201
  background: #18181b;
 
204
  padding: 1.5rem;
205
  margin-top: 2rem;
206
  }
 
207
  .examples-container h3 {
208
  color: #a78bfa;
209
  margin-bottom: 1rem;
210
  font-size: 1.25rem;
211
  font-weight: 600;
212
  }
 
213
  .examples-grid {
214
  display: grid;
215
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
216
  gap: 1rem;
217
  }
 
218
  .example-card {
219
  background: #27272a;
220
  border: 1px solid #3f3f46;
 
223
  cursor: pointer;
224
  transition: all 0.2s;
225
  }
 
226
  .example-card:hover {
227
  background: #374151;
228
  border-color: #6366f1;
229
  transform: translateY(-2px);
230
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
231
  }
 
232
  /* Loading Animation */
233
  .loading-wave {
234
  display: inline-flex;
235
  gap: 4px;
236
  }
 
237
  .loading-wave span {
238
  width: 4px;
239
  height: 20px;
 
241
  border-radius: 2px;
242
  animation: wave 1.2s linear infinite;
243
  }
 
244
  .loading-wave span:nth-child(2) { animation-delay: -1.1s; }
245
  .loading-wave span:nth-child(3) { animation-delay: -1s; }
246
  .loading-wave span:nth-child(4) { animation-delay: -0.9s; }
247
  .loading-wave span:nth-child(5) { animation-delay: -0.8s; }
 
248
  @keyframes wave {
249
  0%, 40%, 100% { transform: scaleY(0.4); }
250
  20% { transform: scaleY(1); }
251
  }
 
252
  /* Report Sections */
253
  .report-section {
254
  background: #1e1b4b;
 
257
  padding: 1.5rem;
258
  margin: 1rem 0;
259
  }
 
260
  .source-badge {
261
  display: inline-block;
262
  background: #374151;
 
266
  font-size: 0.875rem;
267
  margin: 0.25rem;
268
  }
 
269
  /* Export Section */
270
  .export-section {
271
  background: #18181b;
 
275
  margin-top: 2rem;
276
  text-align: center;
277
  }
 
278
  .export-buttons {
279
  display: flex;
280
  gap: 1rem;
281
  justify-content: center;
282
  margin-top: 1.5rem;
283
  }
 
284
  .export-btn {
285
  background: #27272a !important;
286
  border: 1px solid #3f3f46 !important;
 
293
  align-items: center !important;
294
  gap: 0.5rem !important;
295
  }
 
296
  .export-btn:hover {
297
  background: #374151 !important;
298
  border-color: #6366f1 !important;
299
  }
 
300
  /* Responsive */
301
  @media (max-width: 768px) {
302
  .header h1 { font-size: 2.5rem; }
 
462
  plan = research_and_plan(config, planner_model, tavily_client, topic_state, user_input)
463
 
464
  # Show plan
465
+ sections_list = "\n".join([f" {i+1}. **{s.get('title', f'Section {i+1}')}**" for i, s in enumerate(plan['sections'])])
466
  plan_display = f"""
467
  ## 🚀 Starting Deep Research Process
468
 
 
564
  <span style="font-weight: 500;">System Active</span>
565
  </div>
566
  <div style="display: flex; gap: 2rem; align-items: center;">
567
+ <span style="color: #71717a;">Powered by Gemini Flash</span>
568
  <span style="color: #71717a;">Enhanced with Tavily Search</span>
569
  </div>
570
  </div>