Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -413,356 +413,319 @@ coordinator_agent = CoordinatorAgent(message_bus)
|
|
413 |
|
414 |
# Gradio Interface
|
415 |
def create_interface():
|
416 |
-
"""Create
|
417 |
|
418 |
with gr.Blocks(
|
419 |
-
theme=gr.themes.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
420 |
css="""
|
421 |
-
/* Main container styling */
|
422 |
.gradio-container {
|
423 |
max-width: 100vw !important;
|
424 |
margin: 0 !important;
|
425 |
-
padding:
|
426 |
-
background: linear-gradient(135deg, #
|
427 |
min-height: 100vh;
|
428 |
}
|
429 |
-
|
430 |
-
/* Header styling */
|
431 |
.header-container {
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
|
437 |
-
}
|
438 |
-
|
439 |
-
.header-title {
|
440 |
-
font-size: 2.5rem;
|
441 |
-
font-weight: 700;
|
442 |
-
background: linear-gradient(135deg, #667eea, #764ba2);
|
443 |
-webkit-background-clip: text;
|
444 |
-webkit-text-fill-color: transparent;
|
445 |
-
|
|
|
|
|
|
|
|
|
446 |
margin: 0;
|
|
|
|
|
447 |
}
|
448 |
-
|
449 |
.header-subtitle {
|
450 |
-
font-size: 1.
|
451 |
-
color: #6b7280;
|
452 |
-
text-align: center;
|
453 |
margin-top: 0.5rem;
|
|
|
454 |
font-weight: 400;
|
455 |
}
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
backdrop-filter: blur(10px);
|
461 |
-
border
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
}
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
|
|
|
|
|
|
472 |
}
|
473 |
-
|
474 |
-
/* Upload area styling */
|
475 |
.upload-area {
|
476 |
-
|
477 |
-
border:
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
transition: all 0.3s ease;
|
482 |
-
text-align: center;
|
483 |
}
|
484 |
-
|
485 |
.upload-area:hover {
|
486 |
-
border-color: #
|
487 |
-
background:
|
488 |
transform: translateY(-2px);
|
489 |
-
box-shadow: 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
490 |
}
|
491 |
-
|
492 |
-
/* Process button styling */
|
493 |
.process-btn {
|
494 |
-
background: linear-gradient(135deg, #
|
495 |
border: none !important;
|
496 |
-
border-radius:
|
497 |
-
padding:
|
498 |
-
color: white !important;
|
499 |
font-weight: 600 !important;
|
|
|
|
|
500 |
transition: all 0.3s ease !important;
|
501 |
-
box-shadow: 0 4px 15px rgba(
|
502 |
}
|
503 |
-
|
504 |
.process-btn:hover {
|
505 |
transform: translateY(-2px) !important;
|
506 |
-
box-shadow: 0
|
507 |
-
}
|
508 |
-
|
509 |
-
/* Chat container styling */
|
510 |
-
.chat-container {
|
511 |
-
background: rgba(255, 255, 255, 0.95) !important;
|
512 |
-
backdrop-filter: blur(10px);
|
513 |
-
border-radius: 16px !important;
|
514 |
-
margin: 2rem;
|
515 |
-
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1) !important;
|
516 |
-
overflow: hidden;
|
517 |
-
min-height: calc(100vh - 200px);
|
518 |
}
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
border:
|
|
|
|
|
524 |
}
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
border
|
531 |
-
padding: 0.75rem 1.5rem !important;
|
532 |
-
font-size: 1rem !important;
|
533 |
-
transition: all 0.3s ease !important;
|
534 |
}
|
535 |
-
|
536 |
-
.message-input:focus {
|
537 |
-
border-color: #667eea !important;
|
538 |
-
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;
|
539 |
-
outline: none !important;
|
540 |
-
}
|
541 |
-
|
542 |
-
/* Send button styling */
|
543 |
.send-btn {
|
544 |
-
background: linear-gradient(135deg, #
|
545 |
border: none !important;
|
546 |
-
border-radius:
|
547 |
-
|
548 |
-
height: 48px !important;
|
549 |
-
display: flex !important;
|
550 |
-
align-items: center !important;
|
551 |
-
justify-content: center !important;
|
552 |
-
color: white !important;
|
553 |
font-weight: 600 !important;
|
554 |
transition: all 0.3s ease !important;
|
555 |
-
box-shadow: 0 4px 15px rgba(
|
556 |
-
margin-left: 0.5rem !important;
|
557 |
}
|
558 |
-
|
559 |
.send-btn:hover {
|
560 |
-
transform:
|
561 |
-
box-shadow: 0
|
562 |
}
|
563 |
-
|
564 |
-
|
565 |
-
.status-display {
|
566 |
-
background: linear-gradient(135deg, #f0f9ff 0%, #e0e7ff 100%) !important;
|
567 |
-
border: 1px solid rgba(102, 126, 234, 0.2) !important;
|
568 |
-
border-radius: 8px !important;
|
569 |
-
padding: 1rem !important;
|
570 |
-
margin: 1rem 0 !important;
|
571 |
-
font-family: 'SF Mono', 'Monaco', monospace !important;
|
572 |
-
font-size: 0.9rem !important;
|
573 |
}
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
margin-top: 2rem;
|
581 |
-
border: 1px solid rgba(102, 126, 234, 0.1);
|
582 |
}
|
583 |
-
|
584 |
-
|
585 |
-
color: #
|
586 |
-
|
587 |
-
margin-bottom: 1rem;
|
588 |
-
font-size: 1.1rem;
|
589 |
}
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
}
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
|
|
601 |
}
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
background: rgba(255, 255, 255, 0.8) !important;
|
606 |
-
border: 1px solid rgba(102, 126, 234, 0.3) !important;
|
607 |
-
border-radius: 20px !important;
|
608 |
-
padding: 0.5rem 1rem !important;
|
609 |
-
margin: 0.25rem !important;
|
610 |
font-size: 0.9rem !important;
|
611 |
-
color: #374151 !important;
|
612 |
-
transition: all 0.3s ease !important;
|
613 |
}
|
614 |
-
|
615 |
-
|
616 |
-
background: rgba(102, 126, 234, 0.1) !important;
|
617 |
-
border-color: #667eea !important;
|
618 |
-
transform: translateY(-1px) !important;
|
619 |
}
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
.
|
632 |
-
padding: 1rem !important;
|
633 |
-
}
|
634 |
-
|
635 |
-
.chat-container {
|
636 |
-
margin: 1rem;
|
637 |
-
}
|
638 |
}
|
639 |
""",
|
640 |
-
title="
|
641 |
) as iface:
|
642 |
|
643 |
# Header
|
644 |
gr.HTML("""
|
645 |
<div class="header-container">
|
646 |
-
<h1 class="header-title">
|
647 |
-
<p class="header-subtitle">
|
648 |
</div>
|
649 |
""")
|
650 |
|
651 |
-
with gr.Row():
|
652 |
# Sidebar
|
653 |
-
with gr.Column(scale=1,
|
654 |
-
gr.
|
655 |
-
|
656 |
-
file_upload = gr.File(
|
657 |
-
file_count="multiple",
|
658 |
-
file_types=[".pdf", ".pptx", ".csv", ".docx", ".txt", ".md"],
|
659 |
-
label="",
|
660 |
-
elem_classes=["upload-area"],
|
661 |
-
interactive=True
|
662 |
-
)
|
663 |
-
|
664 |
-
process_btn = gr.Button(
|
665 |
-
"🚀 Process Documents",
|
666 |
-
variant="primary",
|
667 |
-
elem_classes=["process-btn"],
|
668 |
-
size="lg"
|
669 |
-
)
|
670 |
-
|
671 |
-
upload_status = gr.Textbox(
|
672 |
-
label="📊 Status",
|
673 |
-
interactive=False,
|
674 |
-
elem_classes=["status-display"],
|
675 |
-
max_lines=4,
|
676 |
-
show_label=True
|
677 |
-
)
|
678 |
-
|
679 |
-
# Info section
|
680 |
-
gr.HTML("""
|
681 |
-
<div class="info-section">
|
682 |
-
<h4>🤖 AI Agents</h4>
|
683 |
-
<p><strong>Ingestion:</strong> Document parsing & preprocessing</p>
|
684 |
-
<p><strong>Retrieval:</strong> Semantic search & context extraction</p>
|
685 |
-
<p><strong>Response:</strong> Intelligent answer generation</p>
|
686 |
-
<p><strong>Coordinator:</strong> Workflow orchestration</p>
|
687 |
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
)
|
703 |
-
|
704 |
-
# Message input area
|
705 |
-
with gr.Row():
|
706 |
-
msg = gr.Textbox(
|
707 |
-
label="",
|
708 |
-
placeholder="Ask me anything about your documents...",
|
709 |
-
scale=10,
|
710 |
-
elem_classes=["message-input"],
|
711 |
-
container=False,
|
712 |
-
autofocus=True
|
713 |
)
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
variant="primary",
|
718 |
-
|
719 |
-
|
|
|
720 |
)
|
721 |
|
722 |
-
|
723 |
-
|
724 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
725 |
gr.Examples(
|
726 |
examples=[
|
727 |
"What are the main topics discussed in the documents?",
|
728 |
-
"Can you summarize the key findings
|
729 |
-
"What metrics
|
730 |
-
"What recommendations
|
731 |
-
"Are there any trends
|
732 |
-
"What are the potential risks or challenges mentioned?"
|
733 |
],
|
734 |
-
inputs=msg
|
|
|
735 |
)
|
736 |
|
737 |
# Event handlers
|
738 |
def process_files_handler(files):
|
739 |
if files:
|
740 |
-
return
|
741 |
-
return "
|
742 |
|
743 |
def respond(message, history):
|
744 |
if message.strip():
|
745 |
-
# Add user message to history
|
746 |
history.append({"role": "user", "content": message})
|
747 |
-
# Add placeholder for assistant response
|
748 |
history.append({"role": "assistant", "content": ""})
|
749 |
|
750 |
# Get streaming response
|
751 |
for token in coordinator_agent.handle_query(message, history):
|
|
|
752 |
history[-1]["content"] += token
|
753 |
-
yield history, ""
|
754 |
else:
|
755 |
yield history, message
|
756 |
|
757 |
-
def clear_chat():
|
758 |
-
return [], ""
|
759 |
-
|
760 |
-
# Event bindings
|
761 |
process_btn.click(
|
762 |
process_files_handler,
|
763 |
inputs=[file_upload],
|
764 |
-
outputs=[upload_status]
|
765 |
-
show_progress=True
|
766 |
)
|
767 |
|
768 |
submit_btn.click(
|
@@ -787,6 +750,5 @@ if __name__ == "__main__":
|
|
787 |
demo.launch(
|
788 |
share=True,
|
789 |
server_name="0.0.0.0",
|
790 |
-
server_port=7860
|
791 |
-
show_error=True
|
792 |
)
|
|
|
413 |
|
414 |
# Gradio Interface
|
415 |
def create_interface():
|
416 |
+
"""Create Gradio interface"""
|
417 |
|
418 |
with gr.Blocks(
|
419 |
+
theme=gr.themes.Base().set(
|
420 |
+
body_background_color="#0b0f19",
|
421 |
+
body_text_color="#ffffff",
|
422 |
+
button_primary_background_fill="#6366f1",
|
423 |
+
button_primary_background_fill_hover="#4f46e5",
|
424 |
+
button_primary_text_color="#ffffff",
|
425 |
+
block_background_fill="#1f2937",
|
426 |
+
block_border_color="#374151",
|
427 |
+
input_background_fill="#374151",
|
428 |
+
input_border_color="#4b5563",
|
429 |
+
input_placeholder_color="#9ca3af",
|
430 |
+
checkbox_background_color="#374151",
|
431 |
+
checkbox_border_color="#4b5563",
|
432 |
+
panel_background_fill="#111827",
|
433 |
+
panel_border_color="#374151",
|
434 |
+
),
|
435 |
css="""
|
|
|
436 |
.gradio-container {
|
437 |
max-width: 100vw !important;
|
438 |
margin: 0 !important;
|
439 |
+
padding: 20px !important;
|
440 |
+
background: linear-gradient(135deg, #0b0f19 0%, #1a1b3a 100%);
|
441 |
min-height: 100vh;
|
442 |
}
|
|
|
|
|
443 |
.header-container {
|
444 |
+
text-align: center;
|
445 |
+
padding: 2rem 0;
|
446 |
+
margin-bottom: 2rem;
|
447 |
+
background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
448 |
-webkit-background-clip: text;
|
449 |
-webkit-text-fill-color: transparent;
|
450 |
+
background-clip: text;
|
451 |
+
}
|
452 |
+
.header-title {
|
453 |
+
font-size: 3.5rem;
|
454 |
+
font-weight: 800;
|
455 |
margin: 0;
|
456 |
+
text-shadow: 0 0 30px rgba(99, 102, 241, 0.5);
|
457 |
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
|
458 |
}
|
|
|
459 |
.header-subtitle {
|
460 |
+
font-size: 1.25rem;
|
|
|
|
|
461 |
margin-top: 0.5rem;
|
462 |
+
color: #9ca3af;
|
463 |
font-weight: 400;
|
464 |
}
|
465 |
+
.sidebar-container {
|
466 |
+
background: rgba(31, 41, 55, 0.8) !important;
|
467 |
+
border-radius: 20px !important;
|
468 |
+
padding: 24px !important;
|
469 |
backdrop-filter: blur(10px);
|
470 |
+
border: 1px solid #374151;
|
471 |
+
height: fit-content;
|
472 |
+
position: sticky;
|
473 |
+
top: 20px;
|
474 |
}
|
475 |
+
.chat-container {
|
476 |
+
background: rgba(31, 41, 55, 0.6) !important;
|
477 |
+
border-radius: 20px !important;
|
478 |
+
padding: 24px !important;
|
479 |
+
backdrop-filter: blur(10px);
|
480 |
+
border: 1px solid #374151;
|
481 |
+
height: calc(100vh - 200px);
|
482 |
+
display: flex;
|
483 |
+
flex-direction: column;
|
484 |
}
|
|
|
|
|
485 |
.upload-area {
|
486 |
+
border: 2px dashed #6366f1 !important;
|
487 |
+
border-radius: 15px !important;
|
488 |
+
padding: 24px !important;
|
489 |
+
margin: 16px 0 !important;
|
490 |
+
background: rgba(99, 102, 241, 0.05) !important;
|
491 |
transition: all 0.3s ease;
|
|
|
492 |
}
|
|
|
493 |
.upload-area:hover {
|
494 |
+
border-color: #8b5cf6 !important;
|
495 |
+
background: rgba(139, 92, 246, 0.1) !important;
|
496 |
transform: translateY(-2px);
|
497 |
+
box-shadow: 0 8px 25px rgba(99, 102, 241, 0.2);
|
498 |
+
}
|
499 |
+
.status-display {
|
500 |
+
background: linear-gradient(135deg, #065f46, #047857) !important;
|
501 |
+
border: none !important;
|
502 |
+
border-radius: 12px !important;
|
503 |
+
color: #ecfdf5 !important;
|
504 |
+
padding: 12px 16px !important;
|
505 |
+
font-family: 'JetBrains Mono', monospace !important;
|
506 |
+
font-size: 0.9rem !important;
|
507 |
}
|
|
|
|
|
508 |
.process-btn {
|
509 |
+
background: linear-gradient(135deg, #6366f1, #8b5cf6) !important;
|
510 |
border: none !important;
|
511 |
+
border-radius: 12px !important;
|
512 |
+
padding: 12px 24px !important;
|
|
|
513 |
font-weight: 600 !important;
|
514 |
+
text-transform: uppercase !important;
|
515 |
+
letter-spacing: 0.5px !important;
|
516 |
transition: all 0.3s ease !important;
|
517 |
+
box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3) !important;
|
518 |
}
|
|
|
519 |
.process-btn:hover {
|
520 |
transform: translateY(-2px) !important;
|
521 |
+
box-shadow: 0 8px 25px rgba(99, 102, 241, 0.4) !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
522 |
}
|
523 |
+
.chatbot-container {
|
524 |
+
flex: 1 !important;
|
525 |
+
background: rgba(17, 24, 39, 0.8) !important;
|
526 |
+
border-radius: 15px !important;
|
527 |
+
border: 1px solid #374151 !important;
|
528 |
+
margin-bottom: 20px !important;
|
529 |
+
overflow: hidden !important;
|
530 |
}
|
531 |
+
.input-row {
|
532 |
+
background: rgba(55, 65, 81, 0.5) !important;
|
533 |
+
border-radius: 15px !important;
|
534 |
+
padding: 16px !important;
|
535 |
+
margin-top: 16px !important;
|
536 |
+
border: 1px solid #4b5563 !important;
|
|
|
|
|
|
|
537 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
538 |
.send-btn {
|
539 |
+
background: linear-gradient(135deg, #10b981, #059669) !important;
|
540 |
border: none !important;
|
541 |
+
border-radius: 10px !important;
|
542 |
+
padding: 12px 20px !important;
|
|
|
|
|
|
|
|
|
|
|
543 |
font-weight: 600 !important;
|
544 |
transition: all 0.3s ease !important;
|
545 |
+
box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3) !important;
|
|
|
546 |
}
|
|
|
547 |
.send-btn:hover {
|
548 |
+
transform: translateY(-2px) !important;
|
549 |
+
box-shadow: 0 8px 25px rgba(16, 185, 129, 0.4) !important;
|
550 |
}
|
551 |
+
.examples-container {
|
552 |
+
margin-top: 16px !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
553 |
}
|
554 |
+
.examples-container .gr-button {
|
555 |
+
background: rgba(75, 85, 99, 0.5) !important;
|
556 |
+
border: 1px solid #6b7280 !important;
|
557 |
+
border-radius: 8px !important;
|
558 |
+
margin: 4px !important;
|
559 |
+
transition: all 0.3s ease !important;
|
|
|
|
|
560 |
}
|
561 |
+
.examples-container .gr-button:hover {
|
562 |
+
background: rgba(99, 102, 241, 0.2) !important;
|
563 |
+
border-color: #6366f1 !important;
|
564 |
+
transform: translateY(-1px) !important;
|
|
|
|
|
565 |
}
|
566 |
+
.architecture-info {
|
567 |
+
background: rgba(17, 24, 39, 0.8) !important;
|
568 |
+
border-radius: 15px !important;
|
569 |
+
padding: 20px !important;
|
570 |
+
margin-top: 24px !important;
|
571 |
+
border: 1px solid #374151 !important;
|
572 |
}
|
573 |
+
.architecture-info h3 {
|
574 |
+
color: #6366f1 !important;
|
575 |
+
margin-bottom: 16px !important;
|
576 |
+
font-size: 1.1rem !important;
|
577 |
+
font-weight: 600 !important;
|
578 |
}
|
579 |
+
.architecture-info p, .architecture-info ul {
|
580 |
+
color: #d1d5db !important;
|
581 |
+
line-height: 1.6 !important;
|
|
|
|
|
|
|
|
|
|
|
582 |
font-size: 0.9rem !important;
|
|
|
|
|
583 |
}
|
584 |
+
.architecture-info ul {
|
585 |
+
margin-left: 16px !important;
|
|
|
|
|
|
|
586 |
}
|
587 |
+
.architecture-info li {
|
588 |
+
margin-bottom: 8px !important;
|
589 |
+
}
|
590 |
+
.gr-textbox {
|
591 |
+
background: rgba(55, 65, 81, 0.8) !important;
|
592 |
+
border: 1px solid #4b5563 !important;
|
593 |
+
border-radius: 12px !important;
|
594 |
+
color: #f9fafb !important;
|
595 |
+
}
|
596 |
+
.gr-textbox:focus {
|
597 |
+
border-color: #6366f1 !important;
|
598 |
+
box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1) !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
599 |
}
|
600 |
""",
|
601 |
+
title="Agentic RAG Chatbot"
|
602 |
) as iface:
|
603 |
|
604 |
# Header
|
605 |
gr.HTML("""
|
606 |
<div class="header-container">
|
607 |
+
<h1 class="header-title">Agentic RAG Chatbot</h1>
|
608 |
+
<p class="header-subtitle">Multi-Format Document QA with Model Context Protocol (MCP)</p>
|
609 |
</div>
|
610 |
""")
|
611 |
|
612 |
+
with gr.Row(equal_height=False):
|
613 |
# Sidebar
|
614 |
+
with gr.Column(scale=1, min_width=350):
|
615 |
+
with gr.Group(elem_classes=["sidebar-container"]):
|
616 |
+
gr.Markdown("### Document Upload", elem_id="upload-title")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
617 |
|
618 |
+
file_upload = gr.File(
|
619 |
+
file_count="multiple",
|
620 |
+
file_types=[".pdf", ".pptx", ".csv", ".docx", ".txt", ".md"],
|
621 |
+
label="Drop files here or click to browse",
|
622 |
+
elem_classes=["upload-area"],
|
623 |
+
scale=4
|
624 |
+
)
|
625 |
+
|
626 |
+
upload_status = gr.Textbox(
|
627 |
+
label="Processing Status",
|
628 |
+
interactive=False,
|
629 |
+
max_lines=4,
|
630 |
+
elem_classes=["status-display"],
|
631 |
+
value="Ready to process documents..."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
632 |
)
|
633 |
+
|
634 |
+
process_btn = gr.Button(
|
635 |
+
"Process Documents",
|
636 |
variant="primary",
|
637 |
+
size="lg",
|
638 |
+
elem_classes=["process-btn"],
|
639 |
+
scale=1
|
640 |
)
|
641 |
|
642 |
+
with gr.Group(elem_classes=["architecture-info"]):
|
643 |
+
gr.Markdown("""
|
644 |
+
### System Architecture
|
645 |
+
|
646 |
+
** Agents:**
|
647 |
+
- **IngestionAgent**: Document parsing & preprocessing
|
648 |
+
- **RetrievalAgent**: Semantic search & embeddings
|
649 |
+
- **LLMResponseAgent**: AI response generation
|
650 |
+
- **CoordinatorAgent**: Workflow orchestration
|
651 |
+
|
652 |
+
**📡 MCP Communication:**
|
653 |
+
Structured message passing between agents for scalable, maintainable AI workflows.
|
654 |
+
|
655 |
+
**🔧 Supported Formats:**
|
656 |
+
PDF, PPTX, CSV, DOCX, TXT, MD
|
657 |
+
""")
|
658 |
+
|
659 |
+
# Main Chat Area
|
660 |
+
with gr.Column(scale=2, min_width=600):
|
661 |
+
with gr.Group(elem_classes=["chat-container"]):
|
662 |
+
gr.Markdown("### 💬 Chat Interface", elem_id="chat-title")
|
663 |
+
|
664 |
+
chatbot = gr.Chatbot(
|
665 |
+
height=550,
|
666 |
+
elem_classes=["chatbot-container"],
|
667 |
+
show_copy_button=True,
|
668 |
+
type="messages",
|
669 |
+
avatar_images=("[( ͡° ͜ʖ ͡°)]", " [¯\_(ツ)_/¯]"),
|
670 |
+
bubble_full_width=False,
|
671 |
+
show_share_button=False
|
672 |
+
)
|
673 |
+
|
674 |
+
with gr.Group(elem_classes=["input-row"]):
|
675 |
+
with gr.Row():
|
676 |
+
msg = gr.Textbox(
|
677 |
+
label="",
|
678 |
+
placeholder="💭 Ask a question about your documents...",
|
679 |
+
scale=4,
|
680 |
+
autofocus=True,
|
681 |
+
container=False,
|
682 |
+
show_label=False
|
683 |
+
)
|
684 |
+
submit_btn = gr.Button(
|
685 |
+
"Send",
|
686 |
+
scale=1,
|
687 |
+
variant="primary",
|
688 |
+
elem_classes=["send-btn"]
|
689 |
+
)
|
690 |
+
|
691 |
+
with gr.Group(elem_classes=["examples-container"]):
|
692 |
gr.Examples(
|
693 |
examples=[
|
694 |
"What are the main topics discussed in the documents?",
|
695 |
+
"Can you summarize the key findings?",
|
696 |
+
"What metrics or KPIs are mentioned?",
|
697 |
+
"What recommendations are provided?",
|
698 |
+
"Are there any trends or patterns identified?"
|
|
|
699 |
],
|
700 |
+
inputs=msg,
|
701 |
+
label="Example Questions"
|
702 |
)
|
703 |
|
704 |
# Event handlers
|
705 |
def process_files_handler(files):
|
706 |
if files:
|
707 |
+
return f" Processing {len(files)} files: {', '.join([os.path.basename(f.name) for f in files])}\n⏳ Please wait..."
|
708 |
+
return "No files uploaded."
|
709 |
|
710 |
def respond(message, history):
|
711 |
if message.strip():
|
712 |
+
# Add user message to history in the new format
|
713 |
history.append({"role": "user", "content": message})
|
714 |
+
# Add a placeholder for the assistant's response
|
715 |
history.append({"role": "assistant", "content": ""})
|
716 |
|
717 |
# Get streaming response
|
718 |
for token in coordinator_agent.handle_query(message, history):
|
719 |
+
# Append each token to the assistant's message content
|
720 |
history[-1]["content"] += token
|
721 |
+
yield history, "" # Yield updated history and clear the textbox
|
722 |
else:
|
723 |
yield history, message
|
724 |
|
|
|
|
|
|
|
|
|
725 |
process_btn.click(
|
726 |
process_files_handler,
|
727 |
inputs=[file_upload],
|
728 |
+
outputs=[upload_status]
|
|
|
729 |
)
|
730 |
|
731 |
submit_btn.click(
|
|
|
750 |
demo.launch(
|
751 |
share=True,
|
752 |
server_name="0.0.0.0",
|
753 |
+
server_port=7860
|
|
|
754 |
)
|