Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -419,365 +419,498 @@ llm_response_agent = LLMResponseAgent(message_bus)
|
|
419 |
coordinator_agent = CoordinatorAgent(message_bus)
|
420 |
|
421 |
def create_interface():
|
422 |
-
"""Create
|
423 |
|
424 |
with gr.Blocks(
|
425 |
-
theme=gr.themes.
|
426 |
css="""
|
427 |
-
/*
|
428 |
.gradio-container {
|
429 |
-
background: #
|
430 |
-
|
431 |
-
font-family: -apple-system, BlinkMacSystemFont,
|
432 |
}
|
433 |
|
434 |
/* Main container */
|
435 |
-
.main-
|
436 |
-
|
437 |
-
|
438 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
439 |
}
|
440 |
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
text-
|
|
|
|
|
|
|
447 |
}
|
448 |
|
449 |
-
.
|
450 |
-
color:
|
|
|
|
|
451 |
margin: 0;
|
452 |
-
|
453 |
-
font-weight: 600;
|
454 |
}
|
455 |
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
|
|
|
|
460 |
}
|
461 |
|
462 |
-
/*
|
463 |
-
.
|
464 |
-
|
465 |
-
|
|
|
|
|
|
|
|
|
466 |
}
|
467 |
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
|
|
474 |
}
|
475 |
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
480 |
}
|
481 |
|
482 |
-
.
|
483 |
-
background:
|
484 |
-
border:
|
485 |
-
|
486 |
}
|
487 |
|
488 |
-
.
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
}
|
493 |
|
494 |
-
/*
|
495 |
-
.
|
496 |
-
background: #
|
497 |
-
|
498 |
-
border
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
499 |
}
|
500 |
|
501 |
-
.
|
502 |
-
|
503 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
504 |
border-radius: 8px;
|
505 |
-
padding:
|
506 |
-
|
|
|
|
|
|
|
|
|
|
|
507 |
}
|
508 |
|
509 |
-
.
|
510 |
-
|
511 |
-
|
512 |
-
font-size: 0.9rem;
|
513 |
}
|
514 |
|
515 |
-
/*
|
516 |
-
.
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
|
|
523 |
}
|
524 |
|
525 |
-
.
|
526 |
-
|
|
|
|
|
527 |
}
|
528 |
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
color: white !important;
|
535 |
-
font-weight: 500 !important;
|
536 |
-
margin-top: 0.5rem !important;
|
537 |
}
|
538 |
|
539 |
-
|
540 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
555 |
-
.gradio-textbox {
|
556 |
flex: 1 !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
557 |
}
|
558 |
|
559 |
-
.
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
font-size: 1rem !important;
|
565 |
-
resize: none !important;
|
566 |
-
min-height: 40px !important;
|
567 |
}
|
568 |
|
569 |
-
|
570 |
-
.
|
571 |
-
|
572 |
-
|
|
|
|
|
|
|
|
|
|
|
573 |
}
|
574 |
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
border:
|
579 |
-
border-radius: 6px !important;
|
580 |
-
color: white !important;
|
581 |
-
min-height: 40px !important;
|
582 |
-
font-weight: 500 !important;
|
583 |
}
|
584 |
|
585 |
-
.
|
586 |
-
background:
|
|
|
|
|
587 |
}
|
588 |
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
border
|
593 |
-
margin: 0.5rem 0;
|
594 |
-
font-size: 0.9rem;
|
595 |
}
|
596 |
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
color: #2ea043;
|
601 |
}
|
602 |
|
603 |
-
.
|
604 |
-
|
605 |
-
|
606 |
-
|
|
|
607 |
}
|
608 |
|
609 |
-
.
|
610 |
-
background: rgba(
|
611 |
-
border: 1px solid
|
612 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
613 |
}
|
614 |
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
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 |
-
/*
|
627 |
-
|
628 |
-
|
|
|
629 |
}
|
630 |
|
631 |
-
|
632 |
-
|
633 |
-
border-radius:
|
634 |
-
background: #161b22;
|
635 |
}
|
636 |
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
border: 1px dashed #30363d !important;
|
641 |
-
border-radius: 6px !important;
|
642 |
}
|
643 |
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
648 |
}
|
649 |
|
650 |
-
.gradio-
|
651 |
-
background:
|
|
|
|
|
|
|
652 |
}
|
653 |
""",
|
654 |
title="Agentic RAG Assistant"
|
655 |
) as iface:
|
656 |
|
657 |
-
#
|
658 |
-
with gr.
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
</
|
665 |
-
|
|
|
666 |
|
667 |
-
|
668 |
-
|
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 |
-
#
|
682 |
-
with gr.Column(elem_classes=["
|
|
|
683 |
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
694 |
)
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
elem_classes=["
|
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 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
|
|
736 |
|
737 |
# State management
|
738 |
doc_processed = gr.State(False)
|
739 |
|
740 |
-
# Event handlers
|
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-
|
748 |
-
|
749 |
</div>
|
750 |
"""
|
751 |
|
752 |
-
# Process files
|
753 |
try:
|
754 |
result = coordinator_agent.process_files(files)
|
755 |
|
756 |
-
# Wait
|
757 |
import time
|
758 |
time.sleep(3)
|
759 |
|
760 |
success_html = """
|
761 |
-
<div class="status-
|
762 |
-
|
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-
|
770 |
-
|
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": "
|
781 |
return history, ""
|
782 |
|
783 |
if not message.strip():
|
@@ -787,21 +920,20 @@ def create_interface():
|
|
787 |
history.append({"role": "user", "content": message})
|
788 |
history.append({"role": "assistant", "content": ""})
|
789 |
|
790 |
-
# Stream response
|
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"
|
797 |
yield history, ""
|
798 |
|
799 |
-
# Event bindings
|
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(
|
|
|
419 |
coordinator_agent = CoordinatorAgent(message_bus)
|
420 |
|
421 |
def create_interface():
|
422 |
+
"""Create enhanced Gradio interface with improved UI"""
|
423 |
|
424 |
with gr.Blocks(
|
425 |
+
theme=gr.themes.Soft(),
|
426 |
css="""
|
427 |
+
/* Global styling */
|
428 |
.gradio-container {
|
429 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
430 |
+
min-height: 100vh;
|
431 |
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
|
432 |
}
|
433 |
|
434 |
/* Main container */
|
435 |
+
.main-wrapper {
|
436 |
+
background: rgba(255, 255, 255, 0.05);
|
437 |
+
backdrop-filter: blur(20px);
|
438 |
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
439 |
+
border-radius: 24px;
|
440 |
+
margin: 20px;
|
441 |
+
padding: 0;
|
442 |
+
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
|
443 |
+
overflow: hidden;
|
444 |
+
}
|
445 |
+
|
446 |
+
/* Header section */
|
447 |
+
.app-header {
|
448 |
+
background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 100%);
|
449 |
+
padding: 24px 32px;
|
450 |
+
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
451 |
+
text-align: center;
|
452 |
}
|
453 |
|
454 |
+
.app-title {
|
455 |
+
font-size: 32px;
|
456 |
+
font-weight: 700;
|
457 |
+
background: linear-gradient(135deg, #ffffff 0%, #e2e8f0 100%);
|
458 |
+
-webkit-background-clip: text;
|
459 |
+
-webkit-text-fill-color: transparent;
|
460 |
+
background-clip: text;
|
461 |
+
margin: 0 0 8px 0;
|
462 |
+
letter-spacing: -0.02em;
|
463 |
}
|
464 |
|
465 |
+
.app-subtitle {
|
466 |
+
color: rgba(255, 255, 255, 0.7);
|
467 |
+
font-size: 16px;
|
468 |
+
font-weight: 400;
|
469 |
margin: 0;
|
470 |
+
line-height: 1.5;
|
|
|
471 |
}
|
472 |
|
473 |
+
/* Content area */
|
474 |
+
.content-area {
|
475 |
+
padding: 32px;
|
476 |
+
display: flex;
|
477 |
+
gap: 32px;
|
478 |
+
min-height: 600px;
|
479 |
}
|
480 |
|
481 |
+
/* Sidebar */
|
482 |
+
.sidebar {
|
483 |
+
flex: 0 0 320px;
|
484 |
+
background: rgba(255, 255, 255, 0.08);
|
485 |
+
border-radius: 16px;
|
486 |
+
padding: 24px;
|
487 |
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
488 |
+
height: fit-content;
|
489 |
}
|
490 |
|
491 |
+
.sidebar-title {
|
492 |
+
color: white;
|
493 |
+
font-size: 18px;
|
494 |
+
font-weight: 600;
|
495 |
+
margin: 0 0 20px 0;
|
496 |
+
padding-bottom: 12px;
|
497 |
+
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
498 |
}
|
499 |
|
500 |
+
/* File upload area */
|
501 |
+
.upload-container {
|
502 |
+
background: rgba(255, 255, 255, 0.05);
|
503 |
+
border: 2px dashed rgba(255, 255, 255, 0.2);
|
504 |
+
border-radius: 12px;
|
505 |
+
padding: 24px;
|
506 |
+
text-align: center;
|
507 |
+
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
508 |
+
margin-bottom: 20px;
|
509 |
+
cursor: pointer;
|
510 |
}
|
511 |
|
512 |
+
.upload-container:hover {
|
513 |
+
background: rgba(255, 255, 255, 0.08);
|
514 |
+
border-color: rgba(255, 255, 255, 0.3);
|
515 |
+
transform: translateY(-2px);
|
516 |
}
|
517 |
|
518 |
+
.upload-text {
|
519 |
+
color: rgba(255, 255, 255, 0.8);
|
520 |
+
font-size: 14px;
|
521 |
+
margin: 8px 0;
|
522 |
}
|
523 |
|
524 |
+
/* Buttons */
|
525 |
+
.primary-button {
|
526 |
+
background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
|
527 |
+
color: white;
|
528 |
+
border: none;
|
529 |
+
border-radius: 12px;
|
530 |
+
padding: 12px 24px;
|
531 |
+
font-weight: 600;
|
532 |
+
font-size: 14px;
|
533 |
+
cursor: pointer;
|
534 |
+
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
535 |
+
box-shadow: 0 4px 14px 0 rgba(59, 130, 246, 0.25);
|
536 |
+
width: 100%;
|
537 |
}
|
538 |
|
539 |
+
.primary-button:hover {
|
540 |
+
transform: translateY(-2px);
|
541 |
+
box-shadow: 0 8px 25px 0 rgba(59, 130, 246, 0.35);
|
542 |
+
}
|
543 |
+
|
544 |
+
.send-button {
|
545 |
+
background: linear-gradient(135deg, #10b981 0%, #059669 100%);
|
546 |
+
color: white;
|
547 |
+
border: none;
|
548 |
border-radius: 8px;
|
549 |
+
padding: 10px 20px;
|
550 |
+
font-weight: 600;
|
551 |
+
font-size: 14px;
|
552 |
+
cursor: pointer;
|
553 |
+
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
554 |
+
box-shadow: 0 2px 8px 0 rgba(16, 185, 129, 0.25);
|
555 |
+
min-width: 80px;
|
556 |
}
|
557 |
|
558 |
+
.send-button:hover {
|
559 |
+
transform: translateY(-1px);
|
560 |
+
box-shadow: 0 4px 12px 0 rgba(16, 185, 129, 0.35);
|
|
|
561 |
}
|
562 |
|
563 |
+
/* Chat area */
|
564 |
+
.chat-section {
|
565 |
+
flex: 1;
|
566 |
+
display: flex;
|
567 |
+
flex-direction: column;
|
568 |
+
background: rgba(255, 255, 255, 0.05);
|
569 |
+
border-radius: 16px;
|
570 |
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
571 |
+
overflow: hidden;
|
572 |
}
|
573 |
|
574 |
+
.chat-header {
|
575 |
+
padding: 20px 24px;
|
576 |
+
background: rgba(255, 255, 255, 0.05);
|
577 |
+
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
578 |
}
|
579 |
|
580 |
+
.chat-title {
|
581 |
+
color: white;
|
582 |
+
font-size: 18px;
|
583 |
+
font-weight: 600;
|
584 |
+
margin: 0;
|
|
|
|
|
|
|
585 |
}
|
586 |
|
587 |
+
/* Chatbot styling */
|
588 |
+
.gradio-chatbot {
|
589 |
+
background: transparent !important;
|
590 |
+
border: none !important;
|
591 |
+
height: 400px !important;
|
592 |
+
max-height: 400px !important;
|
593 |
+
padding: 20px 24px !important;
|
594 |
+
overflow-y: auto !important;
|
595 |
+
}
|
596 |
+
|
597 |
+
/* Message bubbles */
|
598 |
+
.message.user {
|
599 |
+
background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
|
600 |
+
color: white;
|
601 |
+
border-radius: 18px 18px 4px 18px;
|
602 |
+
margin: 8px 0 8px 48px;
|
603 |
+
padding: 12px 16px;
|
604 |
+
max-width: 80%;
|
605 |
+
margin-left: auto;
|
606 |
+
box-shadow: 0 2px 8px rgba(59, 130, 246, 0.2);
|
607 |
+
}
|
608 |
+
|
609 |
+
.message.bot {
|
610 |
+
background: rgba(255, 255, 255, 0.1);
|
611 |
+
color: white;
|
612 |
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
613 |
+
border-radius: 18px 18px 18px 4px;
|
614 |
+
margin: 8px 48px 8px 0;
|
615 |
+
padding: 12px 16px;
|
616 |
+
max-width: 80%;
|
617 |
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
618 |
+
}
|
619 |
+
|
620 |
+
/* Input area */
|
621 |
+
.input-section {
|
622 |
+
padding: 20px 24px;
|
623 |
+
background: rgba(255, 255, 255, 0.05);
|
624 |
+
border-top: 1px solid rgba(255, 255, 255, 0.1);
|
625 |
}
|
626 |
|
|
|
627 |
.input-row {
|
628 |
display: flex !important;
|
629 |
gap: 12px !important;
|
630 |
align-items: end !important;
|
|
|
|
|
|
|
|
|
631 |
}
|
632 |
|
633 |
+
.message-input {
|
|
|
634 |
flex: 1 !important;
|
635 |
+
background: rgba(255, 255, 255, 0.1) !important;
|
636 |
+
border: 1px solid rgba(255, 255, 255, 0.2) !important;
|
637 |
+
border-radius: 12px !important;
|
638 |
+
padding: 12px 16px !important;
|
639 |
+
color: white !important;
|
640 |
+
font-size: 14px !important;
|
641 |
+
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
|
642 |
}
|
643 |
|
644 |
+
.message-input:focus {
|
645 |
+
background: rgba(255, 255, 255, 0.15) !important;
|
646 |
+
border-color: rgba(255, 255, 255, 0.4) !important;
|
647 |
+
box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.1) !important;
|
648 |
+
outline: none !important;
|
|
|
|
|
|
|
649 |
}
|
650 |
|
651 |
+
/* Status indicators */
|
652 |
+
.status-indicator {
|
653 |
+
border-radius: 12px;
|
654 |
+
padding: 16px;
|
655 |
+
margin: 16px 0;
|
656 |
+
font-size: 14px;
|
657 |
+
font-weight: 500;
|
658 |
+
text-align: center;
|
659 |
+
backdrop-filter: blur(10px);
|
660 |
}
|
661 |
|
662 |
+
.status-success {
|
663 |
+
background: rgba(16, 185, 129, 0.15);
|
664 |
+
color: #10b981;
|
665 |
+
border: 1px solid rgba(16, 185, 129, 0.3);
|
|
|
|
|
|
|
|
|
666 |
}
|
667 |
|
668 |
+
.status-error {
|
669 |
+
background: rgba(239, 68, 68, 0.15);
|
670 |
+
color: #ef4444;
|
671 |
+
border: 1px solid rgba(239, 68, 68, 0.3);
|
672 |
}
|
673 |
|
674 |
+
.status-processing {
|
675 |
+
background: rgba(59, 130, 246, 0.15);
|
676 |
+
color: #3b82f6;
|
677 |
+
border: 1px solid rgba(59, 130, 246, 0.3);
|
|
|
|
|
678 |
}
|
679 |
|
680 |
+
/* Examples section */
|
681 |
+
.examples-container {
|
682 |
+
margin-top: 16px;
|
|
|
683 |
}
|
684 |
|
685 |
+
.examples-title {
|
686 |
+
color: rgba(255, 255, 255, 0.8);
|
687 |
+
font-size: 14px;
|
688 |
+
font-weight: 500;
|
689 |
+
margin-bottom: 12px;
|
690 |
}
|
691 |
|
692 |
+
.example-item {
|
693 |
+
background: rgba(255, 255, 255, 0.05);
|
694 |
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
695 |
+
border-radius: 8px;
|
696 |
+
padding: 8px 12px;
|
697 |
+
color: rgba(255, 255, 255, 0.8);
|
698 |
+
font-size: 13px;
|
699 |
+
cursor: pointer;
|
700 |
+
transition: all 0.2s ease;
|
701 |
+
margin-bottom: 6px;
|
702 |
}
|
703 |
|
704 |
+
.example-item:hover {
|
705 |
+
background: rgba(255, 255, 255, 0.1);
|
706 |
+
border-color: rgba(255, 255, 255, 0.2);
|
707 |
+
color: white;
|
|
|
|
|
|
|
|
|
|
|
708 |
}
|
709 |
|
710 |
+
/* Scrollbar styling */
|
711 |
+
::-webkit-scrollbar {
|
712 |
+
width: 6px;
|
713 |
+
height: 6px;
|
714 |
}
|
715 |
|
716 |
+
::-webkit-scrollbar-track {
|
717 |
+
background: rgba(255, 255, 255, 0.1);
|
718 |
+
border-radius: 3px;
|
|
|
719 |
}
|
720 |
|
721 |
+
::-webkit-scrollbar-thumb {
|
722 |
+
background: rgba(255, 255, 255, 0.3);
|
723 |
+
border-radius: 3px;
|
|
|
|
|
724 |
}
|
725 |
|
726 |
+
::-webkit-scrollbar-thumb:hover {
|
727 |
+
background: rgba(255, 255, 255, 0.5);
|
728 |
+
}
|
729 |
+
|
730 |
+
/* Responsive design */
|
731 |
+
@media (max-width: 768px) {
|
732 |
+
.content-area {
|
733 |
+
flex-direction: column;
|
734 |
+
padding: 16px;
|
735 |
+
gap: 16px;
|
736 |
+
}
|
737 |
+
|
738 |
+
.sidebar {
|
739 |
+
flex: none;
|
740 |
+
}
|
741 |
+
|
742 |
+
.main-wrapper {
|
743 |
+
margin: 10px;
|
744 |
+
}
|
745 |
+
|
746 |
+
.app-title {
|
747 |
+
font-size: 24px;
|
748 |
+
}
|
749 |
+
}
|
750 |
+
|
751 |
+
/* Form elements */
|
752 |
+
.gradio-textbox input, .gradio-textbox textarea {
|
753 |
+
background: rgba(255, 255, 255, 0.1) !important;
|
754 |
+
color: white !important;
|
755 |
+
border: 1px solid rgba(255, 255, 255, 0.2) !important;
|
756 |
+
border-radius: 8px !important;
|
757 |
+
}
|
758 |
+
|
759 |
+
.gradio-textbox input:focus, .gradio-textbox textarea:focus {
|
760 |
+
border-color: rgba(255, 255, 255, 0.4) !important;
|
761 |
+
box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1) !important;
|
762 |
+
}
|
763 |
+
|
764 |
+
/* File upload specific styling */
|
765 |
+
.gradio-file {
|
766 |
+
background: transparent !important;
|
767 |
+
border: none !important;
|
768 |
}
|
769 |
|
770 |
+
.gradio-file .file-preview {
|
771 |
+
background: rgba(255, 255, 255, 0.05) !important;
|
772 |
+
border: 1px solid rgba(255, 255, 255, 0.1) !important;
|
773 |
+
border-radius: 8px !important;
|
774 |
+
color: white !important;
|
775 |
}
|
776 |
""",
|
777 |
title="Agentic RAG Assistant"
|
778 |
) as iface:
|
779 |
|
780 |
+
# Main wrapper
|
781 |
+
with gr.Column(elem_classes=["main-wrapper"]):
|
782 |
+
|
783 |
+
# Header
|
784 |
+
gr.HTML("""
|
785 |
+
<div class="app-header">
|
786 |
+
<h1 class="app-title">Agentic RAG Assistant</h1>
|
787 |
+
<p class="app-subtitle">Upload documents and ask questions - powered by Multi-Agent Architecture</p>
|
788 |
+
</div>
|
789 |
+
""")
|
790 |
|
791 |
+
# Content area
|
792 |
+
with gr.Row(elem_classes=["content-area"]):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
793 |
|
794 |
+
# Sidebar
|
795 |
+
with gr.Column(elem_classes=["sidebar"]):
|
796 |
+
gr.HTML('<h3 class="sidebar-title">Document Management</h3>')
|
797 |
|
798 |
+
gr.HTML("""
|
799 |
+
<div class="upload-container">
|
800 |
+
<div class="upload-text">Drag and drop files here or click to browse</div>
|
801 |
+
<div style="color: rgba(255, 255, 255, 0.6); font-size: 12px; margin-top: 8px;">
|
802 |
+
Supported: PDF, PPTX, CSV, DOCX, TXT, MD
|
803 |
+
</div>
|
804 |
+
</div>
|
805 |
+
""")
|
806 |
+
|
807 |
+
file_upload = gr.File(
|
808 |
+
file_count="multiple",
|
809 |
+
file_types=[".pdf", ".pptx", ".csv", ".docx", ".txt", ".md"],
|
810 |
+
label="",
|
811 |
+
show_label=False,
|
812 |
+
container=False
|
813 |
+
)
|
814 |
+
|
815 |
+
processing_status = gr.HTML(visible=False)
|
816 |
+
|
817 |
+
process_btn = gr.Button(
|
818 |
+
"Process Documents",
|
819 |
+
elem_classes=["primary-button"],
|
820 |
+
size="lg"
|
821 |
+
)
|
822 |
+
|
823 |
+
# Chat section
|
824 |
+
with gr.Column(elem_classes=["chat-section"]):
|
825 |
+
|
826 |
+
# Chat header
|
827 |
+
gr.HTML('<div class="chat-header"><h3 class="chat-title">Conversation</h3></div>')
|
828 |
+
|
829 |
+
# Chatbot
|
830 |
+
chatbot = gr.Chatbot(
|
831 |
+
height=400,
|
832 |
+
elem_classes=["gradio-chatbot"],
|
833 |
+
show_copy_button=True,
|
834 |
+
type="messages",
|
835 |
+
placeholder="Upload and process documents to start chatting..."
|
836 |
+
)
|
837 |
+
|
838 |
+
# Input section
|
839 |
+
with gr.Column(elem_classes=["input-section"]):
|
840 |
+
with gr.Row(elem_classes=["input-row"]):
|
841 |
+
msg_input = gr.Textbox(
|
842 |
+
placeholder="Type your question about the uploaded documents...",
|
843 |
+
label="",
|
844 |
+
show_label=False,
|
845 |
+
scale=4,
|
846 |
+
elem_classes=["message-input"],
|
847 |
+
autofocus=True,
|
848 |
+
container=False
|
849 |
)
|
850 |
+
send_btn = gr.Button(
|
851 |
+
"Send",
|
852 |
+
scale=1,
|
853 |
+
elem_classes=["send-button"],
|
854 |
size="sm"
|
855 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
856 |
|
857 |
+
# Examples
|
858 |
+
with gr.Column(elem_classes=["examples-container"]):
|
859 |
+
gr.HTML('<div class="examples-title">Example Questions</div>')
|
860 |
+
gr.Examples(
|
861 |
+
examples=[
|
862 |
+
"What are the main topics discussed?",
|
863 |
+
"Summarize the key findings",
|
864 |
+
"What metrics are mentioned?",
|
865 |
+
"What are the recommendations?"
|
866 |
+
],
|
867 |
+
inputs=msg_input,
|
868 |
+
label="",
|
869 |
+
show_label=False
|
870 |
+
)
|
871 |
|
872 |
# State management
|
873 |
doc_processed = gr.State(False)
|
874 |
|
875 |
+
# Event handlers
|
876 |
def handle_file_upload_and_process(files):
|
877 |
if not files:
|
878 |
return gr.update(visible=False), False
|
879 |
|
880 |
# Show processing indicator
|
881 |
processing_html = f"""
|
882 |
+
<div class="status-indicator status-processing">
|
883 |
+
Processing {len(files)} documents... Please wait.
|
884 |
</div>
|
885 |
"""
|
886 |
|
887 |
+
# Process files
|
888 |
try:
|
889 |
result = coordinator_agent.process_files(files)
|
890 |
|
891 |
+
# Wait for processing
|
892 |
import time
|
893 |
time.sleep(3)
|
894 |
|
895 |
success_html = """
|
896 |
+
<div class="status-indicator status-success">
|
897 |
+
Documents processed successfully! You can now ask questions.
|
898 |
</div>
|
899 |
"""
|
900 |
return gr.update(value=success_html, visible=True), True
|
901 |
|
902 |
except Exception as e:
|
903 |
error_html = f"""
|
904 |
+
<div class="status-indicator status-error">
|
905 |
+
Error processing documents: {str(e)}
|
906 |
</div>
|
907 |
"""
|
908 |
return gr.update(value=error_html, visible=True), False
|
909 |
|
910 |
def respond(message, history, doc_ready):
|
|
|
911 |
if not doc_ready:
|
|
|
912 |
history.append({"role": "user", "content": message})
|
913 |
+
history.append({"role": "assistant", "content": "Please upload and process documents first."})
|
914 |
return history, ""
|
915 |
|
916 |
if not message.strip():
|
|
|
920 |
history.append({"role": "user", "content": message})
|
921 |
history.append({"role": "assistant", "content": ""})
|
922 |
|
923 |
+
# Stream response
|
924 |
try:
|
925 |
for token in coordinator_agent.handle_query(message, history):
|
926 |
history[-1]["content"] += token
|
927 |
yield history, ""
|
928 |
except Exception as e:
|
929 |
+
history[-1]["content"] = f"Error: {str(e)}"
|
930 |
yield history, ""
|
931 |
|
932 |
+
# Event bindings
|
933 |
process_btn.click(
|
934 |
handle_file_upload_and_process,
|
935 |
inputs=[file_upload],
|
936 |
+
outputs=[processing_status, doc_processed]
|
|
|
937 |
)
|
938 |
|
939 |
send_btn.click(
|