MusaR commited on
Commit
77b2456
Β·
verified Β·
1 Parent(s): d27fbee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -50
app.py CHANGED
@@ -21,7 +21,6 @@ if not google_key or not tavily_key:
21
  # Enhanced CSS for a professional research interface
22
  CSS = """
23
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
24
-
25
  :root {
26
  --primary-color: #2563eb;
27
  --primary-hover: #1d4ed8;
@@ -36,19 +35,16 @@ CSS = """
36
  --warning-color: #f59e0b;
37
  --error-color: #ef4444;
38
  }
39
-
40
  body, .gradio-container {
41
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
42
  background-color: var(--bg-primary) !important;
43
  color: var(--text-primary) !important;
44
  }
45
-
46
  .gradio-container {
47
  max-width: 1200px !important;
48
  margin: 0 auto !important;
49
  padding: 2rem !important;
50
  }
51
-
52
  /* Header Styling */
53
  .header-container {
54
  text-align: center;
@@ -58,7 +54,6 @@ body, .gradio-container {
58
  border-radius: 16px;
59
  border: 1px solid var(--border-color);
60
  }
61
-
62
  h1 {
63
  font-size: 3rem;
64
  font-weight: 700;
@@ -67,13 +62,11 @@ h1 {
67
  -webkit-text-fill-color: transparent;
68
  margin-bottom: 0.5rem;
69
  }
70
-
71
  .subtitle {
72
  color: var(--text-secondary);
73
  font-size: 1.25rem;
74
  font-weight: 400;
75
  }
76
-
77
  /* Status Bar */
78
  .status-bar {
79
  background: var(--bg-secondary);
@@ -85,13 +78,11 @@ h1 {
85
  align-items: center;
86
  justify-content: space-between;
87
  }
88
-
89
  .status-indicator {
90
  display: flex;
91
  align-items: center;
92
  gap: 0.5rem;
93
  }
94
-
95
  .status-dot {
96
  width: 8px;
97
  height: 8px;
@@ -99,13 +90,11 @@ h1 {
99
  background: var(--success-color);
100
  animation: pulse 2s infinite;
101
  }
102
-
103
  @keyframes pulse {
104
  0% { opacity: 1; }
105
  50% { opacity: 0.5; }
106
  100% { opacity: 1; }
107
  }
108
-
109
  /* Chat Interface */
110
  #chatbot {
111
  background: var(--bg-secondary) !important;
@@ -113,21 +102,17 @@ h1 {
113
  border-radius: 16px !important;
114
  overflow: hidden !important;
115
  }
116
-
117
  #chatbot .message {
118
  border: none !important;
119
  padding: 1.5rem !important;
120
  }
121
-
122
  #chatbot .user {
123
  background: var(--bg-tertiary) !important;
124
  border-left: 4px solid var(--primary-color) !important;
125
  }
126
-
127
  #chatbot .bot {
128
  background: var(--bg-secondary) !important;
129
  }
130
-
131
  /* Progress Indicators */
132
  .progress-container {
133
  background: var(--bg-tertiary);
@@ -135,7 +120,6 @@ h1 {
135
  padding: 1rem;
136
  margin: 1rem 0;
137
  }
138
-
139
  .progress-bar {
140
  height: 4px;
141
  background: var(--border-color);
@@ -143,20 +127,17 @@ h1 {
143
  overflow: hidden;
144
  margin-top: 0.5rem;
145
  }
146
-
147
  .progress-fill {
148
  height: 100%;
149
  background: linear-gradient(90deg, var(--primary-color) 0%, #60a5fa 100%);
150
  transition: width 0.3s ease;
151
  animation: shimmer 2s infinite;
152
  }
153
-
154
  @keyframes shimmer {
155
  0% { opacity: 0.8; }
156
  50% { opacity: 1; }
157
  100% { opacity: 0.8; }
158
  }
159
-
160
  /* Input Area */
161
  .input-container {
162
  background: var(--bg-secondary);
@@ -165,7 +146,6 @@ h1 {
165
  padding: 1.5rem;
166
  margin-top: 2rem;
167
  }
168
-
169
  #chat-input textarea {
170
  background: var(--bg-tertiary) !important;
171
  color: var(--text-primary) !important;
@@ -175,12 +155,10 @@ h1 {
175
  font-size: 1rem !important;
176
  transition: all 0.2s ease !important;
177
  }
178
-
179
  #chat-input textarea:focus {
180
  border-color: var(--primary-color) !important;
181
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1) !important;
182
  }
183
-
184
  /* Buttons */
185
  .gr-button {
186
  background: var(--primary-color) !important;
@@ -192,22 +170,18 @@ h1 {
192
  transition: all 0.2s ease !important;
193
  cursor: pointer !important;
194
  }
195
-
196
  .gr-button:hover {
197
  background: var(--primary-hover) !important;
198
  transform: translateY(-1px);
199
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3) !important;
200
  }
201
-
202
  .gr-button.secondary {
203
  background: var(--bg-tertiary) !important;
204
  color: var(--text-primary) !important;
205
  }
206
-
207
  .gr-button.secondary:hover {
208
  background: #475569 !important;
209
  }
210
-
211
  /* Report Display */
212
  .report-section {
213
  background: var(--bg-secondary);
@@ -216,7 +190,6 @@ h1 {
216
  padding: 2rem;
217
  margin: 1rem 0;
218
  }
219
-
220
  .report-section h2 {
221
  color: var(--text-primary);
222
  font-size: 1.75rem;
@@ -225,21 +198,18 @@ h1 {
225
  padding-bottom: 0.75rem;
226
  border-bottom: 2px solid var(--border-color);
227
  }
228
-
229
  .report-section h3 {
230
  color: var(--text-secondary);
231
  font-size: 1.25rem;
232
  font-weight: 500;
233
  margin: 1.5rem 0 0.75rem 0;
234
  }
235
-
236
  .source-list {
237
  background: var(--bg-tertiary);
238
  border-radius: 8px;
239
  padding: 1rem;
240
  margin-top: 1rem;
241
  }
242
-
243
  .source-item {
244
  display: flex;
245
  align-items: center;
@@ -249,11 +219,9 @@ h1 {
249
  text-decoration: none;
250
  transition: color 0.2s ease;
251
  }
252
-
253
  .source-item:hover {
254
  color: var(--primary-color);
255
  }
256
-
257
  /* Loading States */
258
  .thinking-indicator {
259
  display: flex;
@@ -262,12 +230,10 @@ h1 {
262
  color: var(--text-secondary);
263
  font-style: italic;
264
  }
265
-
266
  .thinking-dots {
267
  display: flex;
268
  gap: 0.25rem;
269
  }
270
-
271
  .thinking-dots span {
272
  width: 6px;
273
  height: 6px;
@@ -275,15 +241,12 @@ h1 {
275
  border-radius: 50%;
276
  animation: bounce 1.4s infinite ease-in-out both;
277
  }
278
-
279
  .thinking-dots span:nth-child(1) { animation-delay: -0.32s; }
280
  .thinking-dots span:nth-child(2) { animation-delay: -0.16s; }
281
-
282
  @keyframes bounce {
283
  0%, 80%, 100% { transform: scale(0); }
284
  40% { transform: scale(1); }
285
  }
286
-
287
  /* Export Options */
288
  .export-container {
289
  background: var(--bg-secondary);
@@ -292,13 +255,11 @@ h1 {
292
  padding: 1.5rem;
293
  margin-top: 2rem;
294
  }
295
-
296
  .export-buttons {
297
  display: flex;
298
  gap: 1rem;
299
  margin-top: 1rem;
300
  }
301
-
302
  /* Responsive Design */
303
  @media (max-width: 768px) {
304
  .gradio-container {
@@ -427,11 +388,8 @@ def chat_step(user_input, history, current_agent_state, topic_state, progress_st
427
  questions = get_clarifying_questions(planner_model, user_input)
428
  formatted_questions = f"""
429
  ### 🎯 Let's refine your research
430
-
431
  To create the most comprehensive report on **{user_input}**, I'd like to understand your specific interests:
432
-
433
  {questions}
434
-
435
  Please provide your answers below to help me tailor the research to your needs.
436
  """
437
  history[-1] = (user_input, formatted_questions)
@@ -446,16 +404,13 @@ Please provide your answers below to help me tailor the research to your needs.
446
  # Research and planning phase
447
  plan = research_and_plan(config, planner_model, tavily_client, topic_state, user_input)
448
 
449
- # Show research plan
450
- sections_preview = "\n".join([f" {i+1}. {s.title}" for i, s in enumerate(plan['sections'])])
451
  planning_update = f"""
452
  ### πŸ“Š Research Plan Created
453
-
454
  **Topic**: {plan['detailed_topic']}
455
-
456
  **Report Structure**:
457
  {sections_preview}
458
-
459
  Now conducting deep research and writing each section...
460
  """
461
  history[-1] = (user_input, planning_update)
@@ -482,14 +437,11 @@ Now conducting deep research and writing each section...
482
  # Final report display
483
  completion_message = f"""
484
  ### βœ… Research Complete!
485
-
486
  Your comprehensive research report is ready. You can:
487
  - πŸ“₯ Download as PDF using the button below
488
  - πŸ“‹ Copy the text directly from the report
489
  - πŸ”„ Start a new research topic
490
-
491
  ---
492
-
493
  {full_report}
494
  """
495
  history[-1] = (user_input, completion_message)
 
21
  # Enhanced CSS for a professional research interface
22
  CSS = """
23
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
 
24
  :root {
25
  --primary-color: #2563eb;
26
  --primary-hover: #1d4ed8;
 
35
  --warning-color: #f59e0b;
36
  --error-color: #ef4444;
37
  }
 
38
  body, .gradio-container {
39
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
40
  background-color: var(--bg-primary) !important;
41
  color: var(--text-primary) !important;
42
  }
 
43
  .gradio-container {
44
  max-width: 1200px !important;
45
  margin: 0 auto !important;
46
  padding: 2rem !important;
47
  }
 
48
  /* Header Styling */
49
  .header-container {
50
  text-align: center;
 
54
  border-radius: 16px;
55
  border: 1px solid var(--border-color);
56
  }
 
57
  h1 {
58
  font-size: 3rem;
59
  font-weight: 700;
 
62
  -webkit-text-fill-color: transparent;
63
  margin-bottom: 0.5rem;
64
  }
 
65
  .subtitle {
66
  color: var(--text-secondary);
67
  font-size: 1.25rem;
68
  font-weight: 400;
69
  }
 
70
  /* Status Bar */
71
  .status-bar {
72
  background: var(--bg-secondary);
 
78
  align-items: center;
79
  justify-content: space-between;
80
  }
 
81
  .status-indicator {
82
  display: flex;
83
  align-items: center;
84
  gap: 0.5rem;
85
  }
 
86
  .status-dot {
87
  width: 8px;
88
  height: 8px;
 
90
  background: var(--success-color);
91
  animation: pulse 2s infinite;
92
  }
 
93
  @keyframes pulse {
94
  0% { opacity: 1; }
95
  50% { opacity: 0.5; }
96
  100% { opacity: 1; }
97
  }
 
98
  /* Chat Interface */
99
  #chatbot {
100
  background: var(--bg-secondary) !important;
 
102
  border-radius: 16px !important;
103
  overflow: hidden !important;
104
  }
 
105
  #chatbot .message {
106
  border: none !important;
107
  padding: 1.5rem !important;
108
  }
 
109
  #chatbot .user {
110
  background: var(--bg-tertiary) !important;
111
  border-left: 4px solid var(--primary-color) !important;
112
  }
 
113
  #chatbot .bot {
114
  background: var(--bg-secondary) !important;
115
  }
 
116
  /* Progress Indicators */
117
  .progress-container {
118
  background: var(--bg-tertiary);
 
120
  padding: 1rem;
121
  margin: 1rem 0;
122
  }
 
123
  .progress-bar {
124
  height: 4px;
125
  background: var(--border-color);
 
127
  overflow: hidden;
128
  margin-top: 0.5rem;
129
  }
 
130
  .progress-fill {
131
  height: 100%;
132
  background: linear-gradient(90deg, var(--primary-color) 0%, #60a5fa 100%);
133
  transition: width 0.3s ease;
134
  animation: shimmer 2s infinite;
135
  }
 
136
  @keyframes shimmer {
137
  0% { opacity: 0.8; }
138
  50% { opacity: 1; }
139
  100% { opacity: 0.8; }
140
  }
 
141
  /* Input Area */
142
  .input-container {
143
  background: var(--bg-secondary);
 
146
  padding: 1.5rem;
147
  margin-top: 2rem;
148
  }
 
149
  #chat-input textarea {
150
  background: var(--bg-tertiary) !important;
151
  color: var(--text-primary) !important;
 
155
  font-size: 1rem !important;
156
  transition: all 0.2s ease !important;
157
  }
 
158
  #chat-input textarea:focus {
159
  border-color: var(--primary-color) !important;
160
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1) !important;
161
  }
 
162
  /* Buttons */
163
  .gr-button {
164
  background: var(--primary-color) !important;
 
170
  transition: all 0.2s ease !important;
171
  cursor: pointer !important;
172
  }
 
173
  .gr-button:hover {
174
  background: var(--primary-hover) !important;
175
  transform: translateY(-1px);
176
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3) !important;
177
  }
 
178
  .gr-button.secondary {
179
  background: var(--bg-tertiary) !important;
180
  color: var(--text-primary) !important;
181
  }
 
182
  .gr-button.secondary:hover {
183
  background: #475569 !important;
184
  }
 
185
  /* Report Display */
186
  .report-section {
187
  background: var(--bg-secondary);
 
190
  padding: 2rem;
191
  margin: 1rem 0;
192
  }
 
193
  .report-section h2 {
194
  color: var(--text-primary);
195
  font-size: 1.75rem;
 
198
  padding-bottom: 0.75rem;
199
  border-bottom: 2px solid var(--border-color);
200
  }
 
201
  .report-section h3 {
202
  color: var(--text-secondary);
203
  font-size: 1.25rem;
204
  font-weight: 500;
205
  margin: 1.5rem 0 0.75rem 0;
206
  }
 
207
  .source-list {
208
  background: var(--bg-tertiary);
209
  border-radius: 8px;
210
  padding: 1rem;
211
  margin-top: 1rem;
212
  }
 
213
  .source-item {
214
  display: flex;
215
  align-items: center;
 
219
  text-decoration: none;
220
  transition: color 0.2s ease;
221
  }
 
222
  .source-item:hover {
223
  color: var(--primary-color);
224
  }
 
225
  /* Loading States */
226
  .thinking-indicator {
227
  display: flex;
 
230
  color: var(--text-secondary);
231
  font-style: italic;
232
  }
 
233
  .thinking-dots {
234
  display: flex;
235
  gap: 0.25rem;
236
  }
 
237
  .thinking-dots span {
238
  width: 6px;
239
  height: 6px;
 
241
  border-radius: 50%;
242
  animation: bounce 1.4s infinite ease-in-out both;
243
  }
 
244
  .thinking-dots span:nth-child(1) { animation-delay: -0.32s; }
245
  .thinking-dots span:nth-child(2) { animation-delay: -0.16s; }
 
246
  @keyframes bounce {
247
  0%, 80%, 100% { transform: scale(0); }
248
  40% { transform: scale(1); }
249
  }
 
250
  /* Export Options */
251
  .export-container {
252
  background: var(--bg-secondary);
 
255
  padding: 1.5rem;
256
  margin-top: 2rem;
257
  }
 
258
  .export-buttons {
259
  display: flex;
260
  gap: 1rem;
261
  margin-top: 1rem;
262
  }
 
263
  /* Responsive Design */
264
  @media (max-width: 768px) {
265
  .gradio-container {
 
388
  questions = get_clarifying_questions(planner_model, user_input)
389
  formatted_questions = f"""
390
  ### 🎯 Let's refine your research
 
391
  To create the most comprehensive report on **{user_input}**, I'd like to understand your specific interests:
 
392
  {questions}
 
393
  Please provide your answers below to help me tailor the research to your needs.
394
  """
395
  history[-1] = (user_input, formatted_questions)
 
404
  # Research and planning phase
405
  plan = research_and_plan(config, planner_model, tavily_client, topic_state, user_input)
406
 
407
+ # Show research plan - FIXED: Safe access to section titles
408
+ sections_preview = "\n".join([f" {i+1}. {s.get('title', f'Section {i+1}')}" for i, s in enumerate(plan['sections'])])
409
  planning_update = f"""
410
  ### πŸ“Š Research Plan Created
 
411
  **Topic**: {plan['detailed_topic']}
 
412
  **Report Structure**:
413
  {sections_preview}
 
414
  Now conducting deep research and writing each section...
415
  """
416
  history[-1] = (user_input, planning_update)
 
437
  # Final report display
438
  completion_message = f"""
439
  ### βœ… Research Complete!
 
440
  Your comprehensive research report is ready. You can:
441
  - πŸ“₯ Download as PDF using the button below
442
  - πŸ“‹ Copy the text directly from the report
443
  - πŸ”„ Start a new research topic
 
444
  ---
 
445
  {full_report}
446
  """
447
  history[-1] = (user_input, completion_message)