ragunath-ravi commited on
Commit
ef02ed3
Β·
verified Β·
1 Parent(s): 4134b9e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +263 -310
app.py CHANGED
@@ -419,454 +419,407 @@ llm_response_agent = LLMResponseAgent(message_bus)
419
  coordinator_agent = CoordinatorAgent(message_bus)
420
 
421
  def create_interface():
422
- """Create Claude-style Gradio interface with integrated file upload"""
423
 
424
  with gr.Blocks(
425
  theme=gr.themes.Base(),
426
  css="""
427
- /* Claude-inspired dark theme */
428
  .gradio-container {
429
- background-color: #0f0f0f !important;
430
- color: #ffffff !important;
431
- height: 100vh !important;
432
- max-width: none !important;
433
- padding: 0 !important;
434
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif !important;
435
  }
436
 
437
- /* Main layout */
438
  .main-container {
439
- display: flex;
440
- flex-direction: column;
441
- height: 100vh;
442
- background: #0f0f0f;
443
- max-width: 800px;
444
  margin: 0 auto;
 
445
  }
446
 
447
- /* Header - minimal like Claude */
448
- .header {
449
- background: #0f0f0f;
450
- border-bottom: 1px solid #2a2a2a;
451
- padding: 1rem 2rem;
452
  text-align: center;
453
  }
454
 
455
- .header h1 {
456
- color: #ffffff;
457
  margin: 0;
458
- font-size: 1.25rem;
459
- font-weight: 500;
460
  }
461
 
462
- /* Chat container - full height like Claude */
 
 
 
 
 
 
463
  .chat-container {
464
- flex: 1;
465
- display: flex;
466
- flex-direction: column;
467
- padding: 0;
468
- background: #0f0f0f;
469
  }
470
 
471
- /* Chatbot area - Claude style */
472
  .gradio-chatbot {
473
- flex: 1 !important;
474
- height: calc(100vh - 200px) !important;
475
- max-height: none !important;
476
- background: #0f0f0f !important;
477
- border: none !important;
478
- padding: 1rem !important;
479
- overflow-y: auto !important;
480
  }
481
 
482
- /* Messages styling - Claude-like bubbles */
483
- .message.user {
484
- background: #2a2a2a !important;
485
- border-radius: 16px !important;
486
- padding: 12px 16px !important;
487
  margin: 8px 0 !important;
488
- color: #ffffff !important;
489
  }
490
 
491
- .message.bot {
492
- background: transparent !important;
493
- border-radius: 16px !important;
494
- padding: 12px 16px !important;
495
- margin: 8px 0 !important;
496
- color: #ffffff !important;
497
- border-left: 3px solid #ff6b35 !important;
498
- padding-left: 16px !important;
 
 
499
  }
500
 
501
- /* Input area - fixed at bottom like Claude */
502
  .input-container {
503
- position: sticky;
504
- bottom: 0;
505
- background: #0f0f0f;
506
- border-top: 1px solid #2a2a2a;
507
- padding: 1rem 2rem 2rem 2rem;
508
  }
509
 
510
- .input-wrapper {
511
- background: #2a2a2a;
512
- border-radius: 24px;
513
- border: 1px solid #404040;
514
- padding: 4px;
515
- display: flex;
516
- align-items: end;
517
- gap: 8px;
518
- transition: border-color 0.2s;
519
  }
520
 
521
- .input-wrapper:focus-within {
522
- border-color: #ff6b35 !important;
 
 
523
  }
524
 
525
- /* File upload button - integrated like Claude */
526
- .file-btn {
527
- background: transparent !important;
528
  border: none !important;
529
- color: #999999 !important;
530
- padding: 8px !important;
531
- border-radius: 20px !important;
532
- cursor: pointer !important;
533
- display: flex !important;
534
- align-items: center !important;
535
- justify-content: center !important;
536
- min-width: 36px !important;
537
- height: 36px !important;
538
- transition: all 0.2s !important;
 
 
 
 
 
 
 
 
539
  }
540
 
541
- .file-btn:hover {
542
- background: #404040 !important;
543
- color: #ffffff !important;
544
  }
545
 
546
- /* Text input - Claude style */
 
 
 
 
 
 
 
 
 
 
 
547
  .gradio-textbox {
548
  flex: 1 !important;
549
  }
550
 
551
- .gradio-textbox textarea, .gradio-textbox input {
 
552
  background: transparent !important;
553
  border: none !important;
554
- color: #ffffff !important;
 
555
  resize: none !important;
556
- padding: 12px 16px !important;
557
- font-size: 16px !important;
558
- line-height: 1.5 !important;
559
- max-height: 200px !important;
560
- min-height: 24px !important;
561
  }
562
 
563
- .gradio-textbox textarea:focus, .gradio-textbox input:focus {
 
564
  outline: none !important;
565
  box-shadow: none !important;
566
  }
567
 
568
- /* Send button - Claude style */
569
  .send-btn {
570
- background: #ff6b35 !important;
571
  border: none !important;
572
- border-radius: 20px !important;
573
- color: #ffffff !important;
574
- padding: 8px !important;
575
- min-width: 36px !important;
576
- height: 36px !important;
577
- display: flex !important;
578
- align-items: center !important;
579
- justify-content: center !important;
580
- cursor: pointer !important;
581
- transition: all 0.2s !important;
582
  }
583
 
584
  .send-btn:hover {
585
- background: #e55a2b !important;
586
- }
587
-
588
- .send-btn:disabled {
589
- background: #404040 !important;
590
- cursor: not-allowed !important;
591
- }
592
-
593
- /* File upload area - hidden by default */
594
- .file-upload {
595
- display: none !important;
596
  }
597
 
598
  /* Status messages */
599
  .status-message {
600
- background: #1a1a1a;
601
- border: 1px solid #404040;
602
- border-radius: 12px;
603
- padding: 12px 16px;
604
- margin: 8px 0;
605
- color: #cccccc;
606
- font-size: 14px;
607
- text-align: center;
608
  }
609
 
610
  .status-success {
611
- border-color: #22c55e !important;
612
- color: #22c55e !important;
613
- background: rgba(34, 197, 94, 0.1) !important;
614
  }
615
 
616
  .status-error {
617
- border-color: #ef4444 !important;
618
- color: #ef4444 !important;
619
- background: rgba(239, 68, 68, 0.1) !important;
620
  }
621
 
622
  .status-processing {
623
- border-color: #ff6b35 !important;
624
- color: #ff6b35 !important;
625
- background: rgba(255, 107, 53, 0.1) !important;
626
  }
627
 
628
- /* File list styling */
629
  .file-list {
630
- background: #1a1a1a;
631
- border-radius: 8px;
632
- padding: 8px 12px;
633
- margin: 4px 0;
634
- font-size: 14px;
635
- color: #cccccc;
636
- border-left: 3px solid #ff6b35;
637
  }
638
 
639
- /* Hide Gradio elements we don't want */
640
- .gradio-file {
641
- display: none !important;
642
  }
643
 
644
- /* Scrollbar styling */
645
- ::-webkit-scrollbar {
646
- width: 6px;
 
647
  }
648
 
649
- ::-webkit-scrollbar-track {
650
- background: transparent;
 
 
 
651
  }
652
 
653
- ::-webkit-scrollbar-thumb {
654
- background: #404040;
655
- border-radius: 3px;
 
656
  }
657
 
658
- ::-webkit-scrollbar-thumb:hover {
659
- background: #555555;
660
  }
661
  """,
662
  title="Agentic RAG Assistant"
663
  ) as iface:
664
 
665
- # Header - minimal like Claude
666
- gr.HTML("""
667
- <div class="header">
668
- <h1>Agentic RAG Assistant</h1>
669
- </div>
670
- """)
 
 
 
671
 
672
- # Main chat container
673
  with gr.Row():
674
- with gr.Column(scale=1, elem_classes=["main-container"]):
675
 
676
- # Chat area
677
  chatbot = gr.Chatbot(
678
- elem_classes=["gradio-chatbot"],
 
679
  show_copy_button=True,
680
  type="messages",
681
- placeholder="Hello! Upload documents using the πŸ“Ž button below, then ask me anything about them.",
682
- avatar_images=(None, None),
683
- bubble_full_width=False
684
  )
685
 
686
- # Input area - Claude style with integrated file upload
687
- with gr.Row(elem_classes=["input-container"]):
688
- with gr.Column():
689
- with gr.Row(elem_classes=["input-wrapper"]):
690
-
691
- # Hidden file upload
 
 
692
  file_upload = gr.File(
693
  file_count="multiple",
694
  file_types=[".pdf", ".pptx", ".csv", ".docx", ".txt", ".md"],
695
- elem_classes=["file-upload"],
696
- visible=False
697
  )
698
 
699
- # File upload button (πŸ“Ž icon)
700
- file_btn = gr.Button(
701
- "πŸ“Ž",
702
- elem_classes=["file-btn"],
703
- size="sm",
704
- scale=0
705
- )
706
-
707
- # Message input
708
- msg_input = gr.Textbox(
709
- placeholder="Message Agentic RAG Assistant...",
710
- show_label=False,
711
- elem_classes=["message-input"],
712
- scale=1,
713
- container=False,
714
- autofocus=True,
715
- lines=1,
716
- max_lines=10
717
- )
718
-
719
- # Send button
720
- send_btn = gr.Button(
721
- "↑",
722
- elem_classes=["send-btn"],
723
- size="sm",
724
- scale=0
725
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
726
 
727
  # State management
728
  doc_processed = gr.State(False)
729
- uploaded_files = gr.State([])
730
-
731
- # JavaScript for file upload integration
732
- gr.HTML("""
733
- <script>
734
- document.addEventListener('DOMContentLoaded', function() {
735
- // Make file button trigger file upload
736
- const fileBtn = document.querySelector('.file-btn');
737
- const fileInput = document.querySelector('.file-upload input[type="file"]');
738
-
739
- if (fileBtn && fileInput) {
740
- fileBtn.addEventListener('click', function(e) {
741
- e.preventDefault();
742
- e.stopPropagation();
743
- fileInput.click();
744
- });
745
- }
746
-
747
- // Auto-resize textarea
748
- const textarea = document.querySelector('.message-input textarea');
749
- if (textarea) {
750
- textarea.addEventListener('input', function() {
751
- this.style.height = 'auto';
752
- this.style.height = Math.min(this.scrollHeight, 200) + 'px';
753
- });
754
- }
755
- });
756
- </script>
757
- """)
758
 
759
- # Event handlers
760
- def handle_file_upload(files, history):
761
- """Handle file uploads and show in chat"""
762
  if not files:
763
- return history, [], False, gr.update()
764
 
765
- # Add file upload message to chat
766
- file_names = [f.name.split('/')[-1] if hasattr(f, 'name') else str(f) for f in files]
767
- file_list = "\n".join([f"πŸ“„ {name}" for name in file_names])
768
-
769
- history.append({
770
- "role": "user",
771
- "content": f"πŸ“Ž Uploaded {len(files)} file(s):\n{file_list}"
772
- })
773
-
774
- # Show processing message
775
- history.append({
776
- "role": "assistant",
777
- "content": "πŸ“„ Processing documents... This may take a moment."
778
- })
779
 
 
780
  try:
781
- # Process files
782
  result = coordinator_agent.process_files(files)
783
 
784
- # Wait for processing
785
  import time
786
  time.sleep(3)
787
 
788
- # Update last message with success
789
- history[-1]["content"] = f"βœ… Successfully processed {len(files)} document(s)! You can now ask questions about your documents."
790
-
791
- return history, files, True, gr.update(value=None)
 
 
792
 
793
  except Exception as e:
794
- history[-1]["content"] = f"❌ Error processing documents: {str(e)}"
795
- return history, [], False, gr.update(value=None)
 
 
 
 
796
 
797
- def respond(message, history, doc_ready, files):
798
- """Handle user messages"""
799
- if not message.strip():
 
 
 
800
  return history, ""
801
 
 
 
 
802
  # Add user message
803
  history.append({"role": "user", "content": message})
804
-
805
- if not doc_ready and not any(cmd in message.lower() for cmd in ['hello', 'hi', 'help']):
806
- history.append({
807
- "role": "assistant",
808
- "content": "πŸ‘‹ Hello! I'm your RAG assistant. Please upload some documents first using the πŸ“Ž button, then I can help you analyze and answer questions about them."
809
- })
810
- return history, ""
811
-
812
- # Handle general queries without documents
813
- if not doc_ready:
814
- if any(cmd in message.lower() for cmd in ['hello', 'hi', 'help']):
815
- history.append({
816
- "role": "assistant",
817
- "content": "πŸ‘‹ Hello! I'm an AI assistant specialized in document analysis. Upload documents using the πŸ“Ž button above, and I'll help you:\n\nβ€’ Summarize content\nβ€’ Answer questions\nβ€’ Extract key insights\nβ€’ Find specific information\n\nSupported formats: PDF, DOCX, PPTX, CSV, TXT, MD"
818
- })
819
- else:
820
- history.append({
821
- "role": "assistant",
822
- "content": "Please upload documents first using the πŸ“Ž button above, then I can help answer questions about them."
823
- })
824
- return history, ""
825
-
826
- # Add assistant message placeholder
827
  history.append({"role": "assistant", "content": ""})
828
 
829
- # Stream response
830
  try:
831
  for token in coordinator_agent.handle_query(message, history):
832
- if token:
833
- history[-1]["content"] += token
834
- yield history, ""
835
  except Exception as e:
836
- history[-1]["content"] = f"❌ Sorry, I encountered an error: {str(e)}"
837
  yield history, ""
838
-
839
- # Event bindings
840
-
841
- # File upload handling
842
- file_upload.upload(
843
- handle_file_upload,
844
- inputs=[file_upload, chatbot],
845
- outputs=[chatbot, uploaded_files, doc_processed, file_upload]
846
  )
847
-
848
- # File button click (handled by JavaScript)
849
- file_btn.click(None, None, None, js="""
850
- function() {
851
- document.querySelector('.file-upload input[type="file"]').click();
852
- }
853
- """)
854
-
855
- # Send button click
856
  send_btn.click(
857
  respond,
858
- inputs=[msg_input, chatbot, doc_processed, uploaded_files],
859
- outputs=[chatbot, msg_input]
 
860
  )
861
-
862
- # Enter key submit
863
  msg_input.submit(
864
  respond,
865
- inputs=[msg_input, chatbot, doc_processed, uploaded_files],
866
- outputs=[chatbot, msg_input]
 
867
  )
868
 
869
  return iface
 
870
  # Launch the application
871
  if __name__ == "__main__":
872
  demo = create_interface()
 
419
  coordinator_agent = CoordinatorAgent(message_bus)
420
 
421
  def create_interface():
422
+ """Create Claude-style Gradio interface"""
423
 
424
  with gr.Blocks(
425
  theme=gr.themes.Base(),
426
  css="""
427
+ /* Claude-inspired styling */
428
  .gradio-container {
429
+ background: #0d1117 !important;
430
+ color: #e6edf3 !important;
431
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important;
 
 
 
432
  }
433
 
434
+ /* Main container */
435
  .main-container {
436
+ max-width: 900px;
 
 
 
 
437
  margin: 0 auto;
438
+ background: #0d1117;
439
  }
440
 
441
+ /* Header styling */
442
+ .header-container {
443
+ background: #0d1117;
444
+ border-bottom: 1px solid #30363d;
445
+ padding: 1.5rem 0;
446
  text-align: center;
447
  }
448
 
449
+ .header-container h1 {
450
+ color: #f0f6fc;
451
  margin: 0;
452
+ font-size: 1.5rem;
453
+ font-weight: 600;
454
  }
455
 
456
+ .header-container p {
457
+ color: #8b949e;
458
+ margin: 0.5rem 0 0 0;
459
+ font-size: 0.9rem;
460
+ }
461
+
462
+ /* Chat interface */
463
  .chat-container {
464
+ background: #0d1117;
465
+ min-height: 70vh;
 
 
 
466
  }
467
 
468
+ /* Chatbot styling */
469
  .gradio-chatbot {
470
+ background: #0d1117 !important;
471
+ border: 1px solid #30363d !important;
472
+ border-radius: 12px !important;
473
+ min-height: 500px !important;
 
 
 
474
  }
475
 
476
+ .gradio-chatbot .message {
477
+ background: transparent !important;
478
+ border-radius: 8px !important;
 
 
479
  margin: 8px 0 !important;
 
480
  }
481
 
482
+ .gradio-chatbot .message.user {
483
+ background: #21262d !important;
484
+ border: 1px solid #30363d !important;
485
+ color: #f0f6fc !important;
486
+ }
487
+
488
+ .gradio-chatbot .message.bot {
489
+ background: #161b22 !important;
490
+ border-left: 3px solid #fd7e14 !important;
491
+ color: #e6edf3 !important;
492
  }
493
 
494
+ /* Input area styling */
495
  .input-container {
496
+ background: #0d1117;
497
+ padding: 1rem 0;
498
+ border-top: 1px solid #30363d;
 
 
499
  }
500
 
501
+ .upload-section {
502
+ background: #161b22;
503
+ border: 1px solid #30363d;
504
+ border-radius: 8px;
505
+ padding: 1rem;
506
+ margin-bottom: 1rem;
 
 
 
507
  }
508
 
509
+ .upload-section h4 {
510
+ color: #f0f6fc;
511
+ margin: 0 0 0.5rem 0;
512
+ font-size: 0.9rem;
513
  }
514
 
515
+ /* File upload button */
516
+ .upload-btn {
517
+ background: linear-gradient(135deg, #fd7e14, #e8590c) !important;
518
  border: none !important;
519
+ border-radius: 6px !important;
520
+ color: white !important;
521
+ font-weight: 500 !important;
522
+ padding: 0.5rem 1rem !important;
523
+ }
524
+
525
+ .upload-btn:hover {
526
+ background: linear-gradient(135deg, #e8590c, #d63384) !important;
527
+ }
528
+
529
+ /* Process button */
530
+ .process-btn {
531
+ background: #238636 !important;
532
+ border: none !important;
533
+ border-radius: 6px !important;
534
+ color: white !important;
535
+ font-weight: 500 !important;
536
+ margin-top: 0.5rem !important;
537
  }
538
 
539
+ .process-btn:hover {
540
+ background: #2ea043 !important;
 
541
  }
542
 
543
+ /* Input row */
544
+ .input-row {
545
+ display: flex !important;
546
+ gap: 12px !important;
547
+ align-items: end !important;
548
+ background: #161b22;
549
+ border: 1px solid #30363d;
550
+ border-radius: 8px;
551
+ padding: 0.75rem;
552
+ }
553
+
554
+ /* Message input */
555
  .gradio-textbox {
556
  flex: 1 !important;
557
  }
558
 
559
+ .gradio-textbox textarea,
560
+ .gradio-textbox input {
561
  background: transparent !important;
562
  border: none !important;
563
+ color: #f0f6fc !important;
564
+ font-size: 1rem !important;
565
  resize: none !important;
566
+ min-height: 40px !important;
 
 
 
 
567
  }
568
 
569
+ .gradio-textbox textarea:focus,
570
+ .gradio-textbox input:focus {
571
  outline: none !important;
572
  box-shadow: none !important;
573
  }
574
 
575
+ /* Send button */
576
  .send-btn {
577
+ background: #fd7e14 !important;
578
  border: none !important;
579
+ border-radius: 6px !important;
580
+ color: white !important;
581
+ min-height: 40px !important;
582
+ font-weight: 500 !important;
 
 
 
 
 
 
583
  }
584
 
585
  .send-btn:hover {
586
+ background: #e8590c !important;
 
 
 
 
 
 
 
 
 
 
587
  }
588
 
589
  /* Status messages */
590
  .status-message {
591
+ padding: 0.75rem;
592
+ border-radius: 6px;
593
+ margin: 0.5rem 0;
594
+ font-size: 0.9rem;
 
 
 
 
595
  }
596
 
597
  .status-success {
598
+ background: rgba(35, 134, 54, 0.15);
599
+ border: 1px solid #238636;
600
+ color: #2ea043;
601
  }
602
 
603
  .status-error {
604
+ background: rgba(248, 81, 73, 0.15);
605
+ border: 1px solid #da3633;
606
+ color: #f85149;
607
  }
608
 
609
  .status-processing {
610
+ background: rgba(253, 126, 20, 0.15);
611
+ border: 1px solid #fd7e14;
612
+ color: #fd7e14;
613
  }
614
 
615
+ /* File list */
616
  .file-list {
617
+ background: #21262d;
618
+ border-radius: 6px;
619
+ padding: 0.5rem;
620
+ margin: 0.25rem 0;
621
+ font-size: 0.85rem;
622
+ color: #8b949e;
623
+ border-left: 3px solid #fd7e14;
624
  }
625
 
626
+ /* Examples */
627
+ .examples-container {
628
+ margin-top: 1rem;
629
  }
630
 
631
+ .examples-container .gradio-examples {
632
+ border: 1px solid #30363d;
633
+ border-radius: 6px;
634
+ background: #161b22;
635
  }
636
 
637
+ /* Hide default file upload styling */
638
+ .gradio-file {
639
+ background: transparent !important;
640
+ border: 1px dashed #30363d !important;
641
+ border-radius: 6px !important;
642
  }
643
 
644
+ /* Progress bar */
645
+ .gradio-progress {
646
+ background: #21262d !important;
647
+ border-radius: 4px !important;
648
  }
649
 
650
+ .gradio-progress .progress-bar {
651
+ background: #fd7e14 !important;
652
  }
653
  """,
654
  title="Agentic RAG Assistant"
655
  ) as iface:
656
 
657
+ # Header
658
+ with gr.Row():
659
+ with gr.Column(elem_classes=["main-container"]):
660
+ gr.HTML("""
661
+ <div class="header-container">
662
+ <h1>πŸ€– Agentic RAG Assistant</h1>
663
+ <p>Upload documents and ask intelligent questions powered by multi-agent architecture</p>
664
+ </div>
665
+ """)
666
 
667
+ # Main content area
668
  with gr.Row():
669
+ with gr.Column(elem_classes=["main-container"]):
670
 
671
+ # Chat interface
672
  chatbot = gr.Chatbot(
673
+ height=500,
674
+ elem_classes=["chat-container"],
675
  show_copy_button=True,
676
  type="messages",
677
+ placeholder="πŸ‘‹ Welcome! Upload your documents below, then start asking questions.",
678
+ avatar_images=("πŸ‘€", "πŸ€–")
 
679
  )
680
 
681
+ # Input section
682
+ with gr.Column(elem_classes=["input-container"]):
683
+
684
+ # File upload section
685
+ with gr.Group():
686
+ gr.HTML('<div class="upload-section"><h4>πŸ“Ž Document Upload</h4></div>')
687
+
688
+ with gr.Row():
689
  file_upload = gr.File(
690
  file_count="multiple",
691
  file_types=[".pdf", ".pptx", ".csv", ".docx", ".txt", ".md"],
692
+ label="Choose files",
693
+ show_label=False
694
  )
695
 
696
+ process_btn = gr.Button(
697
+ "πŸš€ Process Documents",
698
+ elem_classes=["process-btn"],
699
+ size="sm"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
700
  )
701
+
702
+ # Status display
703
+ processing_status = gr.HTML(visible=False)
704
+
705
+ # Message input section
706
+ with gr.Row(elem_classes=["input-row"]):
707
+ msg_input = gr.Textbox(
708
+ placeholder="Ask me anything about your documents...",
709
+ label="Message",
710
+ show_label=False,
711
+ scale=4,
712
+ autofocus=True,
713
+ container=False
714
+ )
715
+
716
+ send_btn = gr.Button(
717
+ "Send β†—",
718
+ elem_classes=["send-btn"],
719
+ scale=1,
720
+ size="sm"
721
+ )
722
+
723
+ # Example questions
724
+ with gr.Group(elem_classes=["examples-container"]):
725
+ gr.Examples(
726
+ examples=[
727
+ "πŸ“‹ What are the main topics discussed in the documents?",
728
+ "πŸ“Š Can you summarize the key findings and insights?",
729
+ "πŸ” What specific metrics or data points are mentioned?",
730
+ "πŸ’‘ What are the main recommendations or conclusions?"
731
+ ],
732
+ inputs=msg_input,
733
+ label="πŸ’­ Example Questions",
734
+ elem_id="examples"
735
+ )
736
 
737
  # State management
738
  doc_processed = gr.State(False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
739
 
740
+ # Event handlers - keeping original functionality
741
+ def handle_file_upload_and_process(files):
 
742
  if not files:
743
+ return gr.update(visible=False), False
744
 
745
+ # Show processing indicator
746
+ processing_html = f"""
747
+ <div class="status-message status-processing">
748
+ πŸ“„ Processing {len(files)} documents... Please wait.
749
+ </div>
750
+ """
 
 
 
 
 
 
 
 
751
 
752
+ # Process files using original logic
753
  try:
 
754
  result = coordinator_agent.process_files(files)
755
 
756
+ # Wait a moment for processing to complete
757
  import time
758
  time.sleep(3)
759
 
760
+ success_html = """
761
+ <div class="status-message status-success">
762
+ βœ… Documents processed successfully! You can now ask questions.
763
+ </div>
764
+ """
765
+ return gr.update(value=success_html, visible=True), True
766
 
767
  except Exception as e:
768
+ error_html = f"""
769
+ <div class="status-message status-error">
770
+ ❌ Error processing documents: {str(e)}
771
+ </div>
772
+ """
773
+ return gr.update(value=error_html, visible=True), False
774
 
775
+ def respond(message, history, doc_ready):
776
+ # Keep original response logic exactly the same
777
+ if not doc_ready:
778
+ # Show error message
779
+ history.append({"role": "user", "content": message})
780
+ history.append({"role": "assistant", "content": "πŸ“š Please upload and process documents first using the upload section above."})
781
  return history, ""
782
 
783
+ if not message.strip():
784
+ return history, message
785
+
786
  # Add user message
787
  history.append({"role": "user", "content": message})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
788
  history.append({"role": "assistant", "content": ""})
789
 
790
+ # Stream response using original logic
791
  try:
792
  for token in coordinator_agent.handle_query(message, history):
793
+ history[-1]["content"] += token
794
+ yield history, ""
 
795
  except Exception as e:
796
+ history[-1]["content"] = f"οΏ½οΏ½ Error: {str(e)}"
797
  yield history, ""
798
+
799
+ # Event bindings - keeping original functionality
800
+ process_btn.click(
801
+ handle_file_upload_and_process,
802
+ inputs=[file_upload],
803
+ outputs=[processing_status, doc_processed],
804
+ show_progress=True
 
805
  )
806
+
 
 
 
 
 
 
 
 
807
  send_btn.click(
808
  respond,
809
+ inputs=[msg_input, chatbot, doc_processed],
810
+ outputs=[chatbot, msg_input],
811
+ show_progress=True
812
  )
813
+
 
814
  msg_input.submit(
815
  respond,
816
+ inputs=[msg_input, chatbot, doc_processed],
817
+ outputs=[chatbot, msg_input],
818
+ show_progress=True
819
  )
820
 
821
  return iface
822
+
823
  # Launch the application
824
  if __name__ == "__main__":
825
  demo = create_interface()