rdune71 commited on
Commit
3d8ff3e
·
1 Parent(s): bb8594e

hjgjhgjhg

Browse files
Files changed (1) hide show
  1. app.py +85 -74
app.py CHANGED
@@ -60,12 +60,16 @@ class ResearchOrchestrator:
60
  try:
61
  with DDGS() as ddgs:
62
  results = []
 
63
  for r in ddgs.text(query, max_results=5):
 
 
64
  results.append({
65
  'title': r.get('title', 'No title'),
66
  'url': r.get('href', 'No URL'),
67
  'content': r.get('body', 'No content')
68
  })
 
69
  return results
70
  except Exception as e:
71
  logging.error(f"DDG search failed: {e}")
@@ -133,11 +137,18 @@ class ResearchOrchestrator:
133
 
134
  # Collect all streamed content
135
  full_analysis = ""
 
136
  for chunk in self.analyzer.analyze_stream(query, search_results):
137
  if chunk:
138
  full_analysis += chunk
139
- # Yield incremental updates for better streaming
140
- yield full_analysis
 
 
 
 
 
 
141
 
142
  # Check if analysis was successful
143
  if full_analysis.startswith("⚠️") or full_analysis.startswith("Analysis failed"):
@@ -194,7 +205,7 @@ try:
194
  with open("version.json", "r") as f:
195
  VERSION = json.load(f)
196
  except FileNotFoundError:
197
- VERSION = {"version": "133", "description": "Initial release"}
198
 
199
  # Initialize modules with error handling
200
  def initialize_modules():
@@ -225,7 +236,7 @@ def initialize_modules():
225
  # Initialize orchestrator
226
  orchestrator = initialize_modules()
227
 
228
- # Custom CSS for enhanced UI with improved visibility
229
  custom_css = """
230
  /* Reset and base styles */
231
  * {
@@ -237,8 +248,8 @@ custom_css = """
237
  html, body {
238
  height: 100%;
239
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
240
- background-color: #2c3e50 !important;
241
- color: #ecf0f1 !important;
242
  line-height: 1.6;
243
  }
244
 
@@ -254,10 +265,10 @@ html, body {
254
  text-align: center;
255
  margin-bottom: 30px;
256
  padding: 25px;
257
- background: linear-gradient(135deg, #3498db, #2980b9);
258
  color: white;
259
  border-radius: 12px;
260
- box-shadow: 0 6px 15px rgba(0, 0, 0, 0.3);
261
  }
262
 
263
  .title {
@@ -283,44 +294,44 @@ html, body {
283
 
284
  /* Card styles */
285
  .card {
286
- background: #34495e !important;
287
  border-radius: 12px;
288
- box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
289
  padding: 25px;
290
  margin-bottom: 25px;
291
  transition: all 0.3s ease;
292
- border: 1px solid #2c3e50;
293
- color: #ecf0f1 !important;
294
  }
295
 
296
  .card:hover {
297
  transform: translateY(-3px);
298
- box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
299
  }
300
 
301
  .input-section {
302
- background: linear-gradient(to bottom right, #2c3e50, #34495e);
303
- border: 1px solid #3498db;
304
  }
305
 
306
  .output-section {
307
- background: #2c3e50 !important;
308
- border: 1px solid #3498db;
309
  }
310
 
311
  /* Section headings */
312
  .card h3 {
313
- color: #3498db !important;
314
  margin-bottom: 20px;
315
  font-size: 1.4rem;
316
  font-weight: 600;
317
- border-bottom: 2px solid #3498db;
318
  padding-bottom: 10px;
319
  }
320
 
321
  /* Button styles */
322
  .btn-primary {
323
- background: linear-gradient(135deg, #3498db, #2980b9);
324
  color: white !important;
325
  border: none;
326
  padding: 14px 28px;
@@ -329,7 +340,7 @@ html, body {
329
  cursor: pointer;
330
  transition: all 0.3s ease;
331
  font-weight: 600;
332
- box-shadow: 0 4px 10px rgba(52, 152, 219, 0.4);
333
  display: inline-block;
334
  width: 100%;
335
  text-align: center;
@@ -337,20 +348,20 @@ html, body {
337
 
338
  .btn-primary:hover {
339
  transform: translateY(-3px);
340
- box-shadow: 0 6px 15px rgba(52, 152, 219, 0.6);
341
- background: linear-gradient(135deg, #2980b9, #1c6ea4);
342
  }
343
 
344
  .btn-primary:active {
345
  transform: translateY(1px);
346
- box-shadow: 0 2px 5px rgba(52, 152, 219, 0.4);
347
  }
348
 
349
  /* Input fields */
350
  .gr-textbox, .gr-textbox input, .gr-textbox textarea {
351
- color: #ecf0f1 !important;
352
- background-color: #34495e !important;
353
- border: 2px solid #3498db !important;
354
  border-radius: 8px !important;
355
  padding: 12px 15px !important;
356
  font-size: 16px !important;
@@ -359,22 +370,22 @@ html, body {
359
  }
360
 
361
  .gr-textbox:focus, .gr-textbox input:focus, .gr-textbox textarea:focus {
362
- border-color: #1abc9c !important;
363
- box-shadow: 0 0 0 3px rgba(26, 188, 156, 0.3) !important;
364
  }
365
 
366
  /* File upload */
367
  .gr-file {
368
- border: 2px dashed #3498db !important;
369
  border-radius: 8px !important;
370
  padding: 15px !important;
371
- background-color: #34495e !important;
372
- color: #ecf0f1 !important;
373
  }
374
 
375
  .gr-file:hover {
376
- border-color: #1abc9c !important;
377
- background-color: #2c3e50 !important;
378
  }
379
 
380
  /* Checkbox */
@@ -384,7 +395,7 @@ html, body {
384
 
385
  .gr-checkbox label {
386
  font-size: 16px;
387
- color: #ecf0f1 !important;
388
  display: flex;
389
  align-items: center;
390
  }
@@ -393,30 +404,30 @@ html, body {
393
  .streaming-content {
394
  white-space: pre-wrap;
395
  font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
396
- background-color: #34495e !important;
397
  padding: 20px;
398
  border-radius: 10px;
399
  margin: 15px 0;
400
- border-left: 5px solid #3498db;
401
- box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.3);
402
  min-height: 150px;
403
  max-height: 700px;
404
  overflow-y: auto;
405
- color: #ecf0f1 !important;
406
  font-size: 16px;
407
  line-height: 1.7;
408
- border: 1px solid #2c3e50;
409
  }
410
 
411
  .streaming-content h2 {
412
- color: #3498db !important;
413
- border-bottom: 2px solid #3498db;
414
  padding-bottom: 10px;
415
  margin-top: 0;
416
  }
417
 
418
  .streaming-content h3 {
419
- color: #1abc9c !important;
420
  margin-top: 20px;
421
  }
422
 
@@ -435,17 +446,17 @@ html, body {
435
  align-items: center;
436
  justify-content: center;
437
  padding: 12px;
438
- background: #34495e;
439
  border-radius: 8px;
440
  margin: 15px 0;
441
- color: #3498db;
442
  font-weight: 500;
443
- border: 1px solid #3498db;
444
  }
445
 
446
  .spinner {
447
- border: 4px solid #2c3e50;
448
- border-top: 4px solid #3498db;
449
  border-radius: 50%;
450
  width: 24px;
451
  height: 24px;
@@ -457,7 +468,7 @@ html, body {
457
  .progress-text {
458
  margin-left: 10px;
459
  font-weight: 500;
460
- color: #ecf0f1 !important;
461
  }
462
 
463
  /* Footer */
@@ -465,20 +476,20 @@ html, body {
465
  text-align: center;
466
  margin-top: 30px;
467
  padding: 25px;
468
- color: #bdc3c7 !important;
469
  font-size: 0.95rem;
470
- background: #34495e;
471
  border-radius: 10px;
472
- border-top: 1px solid #3498db;
473
  }
474
 
475
  .footer p {
476
  margin: 8px 0;
477
- color: #ecf0f1 !important;
478
  }
479
 
480
  .highlight {
481
- background: linear-gradient(120deg, #3498db, #2980b9);
482
  padding: 3px 8px;
483
  border-radius: 5px;
484
  font-weight: 600;
@@ -487,47 +498,47 @@ html, body {
487
 
488
  /* Markdown content */
489
  .gr-markdown {
490
- color: #ecf0f1 !important;
491
  line-height: 1.7;
492
- background-color: #34495e !important;
493
  }
494
 
495
  .gr-markdown h1, .gr-markdown h2, .gr-markdown h3,
496
  .gr-markdown h4, .gr-markdown h5, .gr-markdown h6 {
497
- color: #3498db !important;
498
  margin-top: 1.5rem;
499
  margin-bottom: 1rem;
500
  }
501
 
502
  .gr-markdown p {
503
- color: #ecf0f1 !important;
504
  margin-bottom: 1rem;
505
  }
506
 
507
  .gr-markdown a {
508
- color: #1abc9c !important;
509
  text-decoration: underline;
510
  }
511
 
512
  .gr-markdown a:hover {
513
- color: #16a085 !important;
514
  }
515
 
516
  .gr-markdown code {
517
- background-color: #2c3e50 !important;
518
  padding: 2px 6px !important;
519
  border-radius: 4px !important;
520
- color: #f39c12 !important;
521
  font-size: 0.95em !important;
522
  }
523
 
524
  .gr-markdown pre {
525
- background-color: #2c3e50 !important;
526
  padding: 15px !important;
527
  border-radius: 8px !important;
528
  overflow-x: auto !important;
529
- color: #ecf0f1 !important;
530
- border: 1px solid #3498db !important;
531
  }
532
 
533
  .gr-markdown pre code {
@@ -537,12 +548,12 @@ html, body {
537
  }
538
 
539
  .gr-markdown blockquote {
540
- border-left: 4px solid #3498db !important;
541
  padding: 10px 20px !important;
542
- background-color: #2c3e50 !important;
543
  margin: 20px 0 !important;
544
  border-radius: 0 8px 8px 0 !important;
545
- color: #ecf0f1 !important;
546
  }
547
 
548
  .gr-markdown table {
@@ -552,14 +563,14 @@ html, body {
552
  }
553
 
554
  .gr-markdown table th, .gr-markdown table td {
555
- border: 1px solid #3498db !important;
556
  padding: 10px !important;
557
  text-align: left !important;
558
- color: #ecf0f1 !important;
559
  }
560
 
561
  .gr-markdown table th {
562
- background-color: #2980b9 !important;
563
  color: #ffffff !important;
564
  }
565
 
@@ -605,7 +616,7 @@ html, body {
605
  /* High contrast mode support */
606
  @media (prefers-contrast: high) {
607
  body {
608
- background-color: #1a1a1a !important;
609
  color: #ffffff !important;
610
  }
611
 
@@ -627,7 +638,7 @@ with gr.Blocks(css=custom_css, title="Research Assistant") as demo:
627
  <div class="header">
628
  <h1 class="title">🧠 AI Research Assistant</h1>
629
  <p class="subtitle">Your intelligent research companion</p>
630
- <div class="version-info">🧬 Version: {VERSION['version']} | {VERSION['description']}</div>
631
  </div>
632
  """)
633
 
@@ -681,4 +692,4 @@ with gr.Blocks(css=custom_css, title="Research Assistant") as demo:
681
  """)
682
 
683
  if __name__ == "__main__":
684
- demo.launch(share=True)
 
60
  try:
61
  with DDGS() as ddgs:
62
  results = []
63
+ count = 0
64
  for r in ddgs.text(query, max_results=5):
65
+ if count >= 5: # Limit to 5 results
66
+ break
67
  results.append({
68
  'title': r.get('title', 'No title'),
69
  'url': r.get('href', 'No URL'),
70
  'content': r.get('body', 'No content')
71
  })
72
+ count += 1
73
  return results
74
  except Exception as e:
75
  logging.error(f"DDG search failed: {e}")
 
137
 
138
  # Collect all streamed content
139
  full_analysis = ""
140
+ last_yielded = ""
141
  for chunk in self.analyzer.analyze_stream(query, search_results):
142
  if chunk:
143
  full_analysis += chunk
144
+ # Only yield when we have significant new content to avoid excessive updates
145
+ if len(full_analysis) - len(last_yielded) > 100 or "✅" in chunk or "⚠️" in chunk:
146
+ last_yielded = full_analysis
147
+ yield full_analysis
148
+
149
+ # Final yield to ensure complete content is displayed
150
+ if full_analysis != last_yielded:
151
+ yield full_analysis
152
 
153
  # Check if analysis was successful
154
  if full_analysis.startswith("⚠️") or full_analysis.startswith("Analysis failed"):
 
205
  with open("version.json", "r") as f:
206
  VERSION = json.load(f)
207
  except FileNotFoundError:
208
+ VERSION = {"version": "133", "description": "Enhanced assistant with file upload, DDG search, multi-language support"}
209
 
210
  # Initialize modules with error handling
211
  def initialize_modules():
 
236
  # Initialize orchestrator
237
  orchestrator = initialize_modules()
238
 
239
+ # Custom CSS for enhanced UI with improved visibility and contrast
240
  custom_css = """
241
  /* Reset and base styles */
242
  * {
 
248
  html, body {
249
  height: 100%;
250
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
251
+ background-color: #1e1e2e !important;
252
+ color: #e0e0e0 !important;
253
  line-height: 1.6;
254
  }
255
 
 
265
  text-align: center;
266
  margin-bottom: 30px;
267
  padding: 25px;
268
+ background: linear-gradient(135deg, #2563eb, #1d4ed8);
269
  color: white;
270
  border-radius: 12px;
271
+ box-shadow: 0 6px 15px rgba(0, 0, 0, 0.4);
272
  }
273
 
274
  .title {
 
294
 
295
  /* Card styles */
296
  .card {
297
+ background: #2d2d44 !important;
298
  border-radius: 12px;
299
+ box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4);
300
  padding: 25px;
301
  margin-bottom: 25px;
302
  transition: all 0.3s ease;
303
+ border: 1px solid #3b82f6;
304
+ color: #e0e0e0 !important;
305
  }
306
 
307
  .card:hover {
308
  transform: translateY(-3px);
309
+ box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
310
  }
311
 
312
  .input-section {
313
+ background: linear-gradient(to bottom right, #1e293b, #334155);
314
+ border: 1px solid #3b82f6;
315
  }
316
 
317
  .output-section {
318
+ background: #1e293b !important;
319
+ border: 1px solid #3b82f6;
320
  }
321
 
322
  /* Section headings */
323
  .card h3 {
324
+ color: #60a5fa !important;
325
  margin-bottom: 20px;
326
  font-size: 1.4rem;
327
  font-weight: 600;
328
+ border-bottom: 2px solid #3b82f6;
329
  padding-bottom: 10px;
330
  }
331
 
332
  /* Button styles */
333
  .btn-primary {
334
+ background: linear-gradient(135deg, #2563eb, #1d4ed8);
335
  color: white !important;
336
  border: none;
337
  padding: 14px 28px;
 
340
  cursor: pointer;
341
  transition: all 0.3s ease;
342
  font-weight: 600;
343
+ box-shadow: 0 4px 10px rgba(37, 99, 235, 0.4);
344
  display: inline-block;
345
  width: 100%;
346
  text-align: center;
 
348
 
349
  .btn-primary:hover {
350
  transform: translateY(-3px);
351
+ box-shadow: 0 6px 15px rgba(37, 99, 235, 0.6);
352
+ background: linear-gradient(135deg, #1d4ed8, #1e40af);
353
  }
354
 
355
  .btn-primary:active {
356
  transform: translateY(1px);
357
+ box-shadow: 0 2px 5px rgba(37, 99, 235, 0.4);
358
  }
359
 
360
  /* Input fields */
361
  .gr-textbox, .gr-textbox input, .gr-textbox textarea {
362
+ color: #e0e0e0 !important;
363
+ background-color: #334155 !important;
364
+ border: 2px solid #3b82f6 !important;
365
  border-radius: 8px !important;
366
  padding: 12px 15px !important;
367
  font-size: 16px !important;
 
370
  }
371
 
372
  .gr-textbox:focus, .gr-textbox input:focus, .gr-textbox textarea:focus {
373
+ border-color: #06b6d4 !important;
374
+ box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.3) !important;
375
  }
376
 
377
  /* File upload */
378
  .gr-file {
379
+ border: 2px dashed #3b82f6 !important;
380
  border-radius: 8px !important;
381
  padding: 15px !important;
382
+ background-color: #334155 !important;
383
+ color: #e0e0e0 !important;
384
  }
385
 
386
  .gr-file:hover {
387
+ border-color: #06b6d4 !important;
388
+ background-color: #1e293b !important;
389
  }
390
 
391
  /* Checkbox */
 
395
 
396
  .gr-checkbox label {
397
  font-size: 16px;
398
+ color: #e0e0e0 !important;
399
  display: flex;
400
  align-items: center;
401
  }
 
404
  .streaming-content {
405
  white-space: pre-wrap;
406
  font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
407
+ background-color: #1e293b !important;
408
  padding: 20px;
409
  border-radius: 10px;
410
  margin: 15px 0;
411
+ border-left: 5px solid #3b82f6;
412
+ box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.4);
413
  min-height: 150px;
414
  max-height: 700px;
415
  overflow-y: auto;
416
+ color: #e0e0e0 !important;
417
  font-size: 16px;
418
  line-height: 1.7;
419
+ border: 1px solid #374151;
420
  }
421
 
422
  .streaming-content h2 {
423
+ color: #60a5fa !important;
424
+ border-bottom: 2px solid #3b82f6;
425
  padding-bottom: 10px;
426
  margin-top: 0;
427
  }
428
 
429
  .streaming-content h3 {
430
+ color: #06b6d4 !important;
431
  margin-top: 20px;
432
  }
433
 
 
446
  align-items: center;
447
  justify-content: center;
448
  padding: 12px;
449
+ background: #334155;
450
  border-radius: 8px;
451
  margin: 15px 0;
452
+ color: #60a5fa;
453
  font-weight: 500;
454
+ border: 1px solid #3b82f6;
455
  }
456
 
457
  .spinner {
458
+ border: 4px solid #1e293b;
459
+ border-top: 4px solid #3b82f6;
460
  border-radius: 50%;
461
  width: 24px;
462
  height: 24px;
 
468
  .progress-text {
469
  margin-left: 10px;
470
  font-weight: 500;
471
+ color: #e0e0e0 !important;
472
  }
473
 
474
  /* Footer */
 
476
  text-align: center;
477
  margin-top: 30px;
478
  padding: 25px;
479
+ color: #9ca3af !important;
480
  font-size: 0.95rem;
481
+ background: #1e293b;
482
  border-radius: 10px;
483
+ border-top: 1px solid #3b82f6;
484
  }
485
 
486
  .footer p {
487
  margin: 8px 0;
488
+ color: #e0e0e0 !important;
489
  }
490
 
491
  .highlight {
492
+ background: linear-gradient(120deg, #2563eb, #1d4ed8);
493
  padding: 3px 8px;
494
  border-radius: 5px;
495
  font-weight: 600;
 
498
 
499
  /* Markdown content */
500
  .gr-markdown {
501
+ color: #e0e0e0 !important;
502
  line-height: 1.7;
503
+ background-color: #1e293b !important;
504
  }
505
 
506
  .gr-markdown h1, .gr-markdown h2, .gr-markdown h3,
507
  .gr-markdown h4, .gr-markdown h5, .gr-markdown h6 {
508
+ color: #60a5fa !important;
509
  margin-top: 1.5rem;
510
  margin-bottom: 1rem;
511
  }
512
 
513
  .gr-markdown p {
514
+ color: #e0e0e0 !important;
515
  margin-bottom: 1rem;
516
  }
517
 
518
  .gr-markdown a {
519
+ color: #06b6d4 !important;
520
  text-decoration: underline;
521
  }
522
 
523
  .gr-markdown a:hover {
524
+ color: #0891b2 !important;
525
  }
526
 
527
  .gr-markdown code {
528
+ background-color: #334155 !important;
529
  padding: 2px 6px !important;
530
  border-radius: 4px !important;
531
+ color: #f59e0b !important;
532
  font-size: 0.95em !important;
533
  }
534
 
535
  .gr-markdown pre {
536
+ background-color: #334155 !important;
537
  padding: 15px !important;
538
  border-radius: 8px !important;
539
  overflow-x: auto !important;
540
+ color: #e0e0e0 !important;
541
+ border: 1px solid #3b82f6 !important;
542
  }
543
 
544
  .gr-markdown pre code {
 
548
  }
549
 
550
  .gr-markdown blockquote {
551
+ border-left: 4px solid #3b82f6 !important;
552
  padding: 10px 20px !important;
553
+ background-color: #1e293b !important;
554
  margin: 20px 0 !important;
555
  border-radius: 0 8px 8px 0 !important;
556
+ color: #e0e0e0 !important;
557
  }
558
 
559
  .gr-markdown table {
 
563
  }
564
 
565
  .gr-markdown table th, .gr-markdown table td {
566
+ border: 1px solid #3b82f6 !important;
567
  padding: 10px !important;
568
  text-align: left !important;
569
+ color: #e0e0e0 !important;
570
  }
571
 
572
  .gr-markdown table th {
573
+ background-color: #1d4ed8 !important;
574
  color: #ffffff !important;
575
  }
576
 
 
616
  /* High contrast mode support */
617
  @media (prefers-contrast: high) {
618
  body {
619
+ background-color: #000000 !important;
620
  color: #ffffff !important;
621
  }
622
 
 
638
  <div class="header">
639
  <h1 class="title">🧠 AI Research Assistant</h1>
640
  <p class="subtitle">Your intelligent research companion</p>
641
+ <div class="version-info">🧬 Version: {VERSION['version']}</div>
642
  </div>
643
  """)
644
 
 
692
  """)
693
 
694
  if __name__ == "__main__":
695
+ demo.launch(share=True)