Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -419,455 +419,520 @@ llm_response_agent = LLMResponseAgent(message_bus)
|
|
419 |
coordinator_agent = CoordinatorAgent(message_bus)
|
420 |
|
421 |
def create_interface():
|
422 |
-
"""Create enhanced Gradio interface with
|
423 |
|
424 |
with gr.Blocks(
|
425 |
-
theme=gr.themes.
|
426 |
css="""
|
427 |
-
/*
|
|
|
|
|
|
|
428 |
.gradio-container {
|
429 |
-
background: linear-gradient(135deg, #
|
430 |
-
|
431 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
432 |
}
|
433 |
|
434 |
-
/*
|
435 |
-
.
|
436 |
-
background: rgba(255,
|
|
|
|
|
|
|
437 |
backdrop-filter: blur(20px);
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
|
443 |
overflow: hidden;
|
444 |
}
|
445 |
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
452 |
}
|
453 |
|
454 |
-
.
|
455 |
-
|
|
|
|
|
456 |
font-weight: 700;
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
background-clip: text;
|
461 |
-
margin: 0 0 8px 0;
|
462 |
letter-spacing: -0.02em;
|
463 |
}
|
464 |
|
465 |
-
.
|
466 |
-
color:
|
467 |
-
|
|
|
468 |
font-weight: 400;
|
469 |
-
|
470 |
-
line-height: 1.5;
|
471 |
}
|
472 |
|
473 |
-
/*
|
474 |
-
.
|
475 |
-
|
476 |
display: flex;
|
477 |
-
|
478 |
-
|
|
|
|
|
|
|
|
|
|
|
479 |
}
|
480 |
|
481 |
-
/*
|
482 |
-
.
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
border:
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
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 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
516 |
}
|
517 |
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
522 |
}
|
523 |
|
524 |
-
|
525 |
-
|
526 |
-
|
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 |
-
|
540 |
-
|
541 |
-
|
|
|
|
|
|
|
|
|
|
|
542 |
}
|
543 |
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
border:
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
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 |
-
|
559 |
-
|
560 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
561 |
}
|
562 |
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
|
|
|
|
|
|
|
|
572 |
}
|
573 |
|
574 |
-
|
575 |
-
|
576 |
-
background: rgba(255,
|
577 |
-
border
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
578 |
}
|
579 |
|
580 |
-
.
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
|
|
|
|
585 |
}
|
586 |
|
587 |
-
/*
|
588 |
-
.
|
589 |
-
background:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
590 |
border: none !important;
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
595 |
}
|
596 |
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
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 |
-
.
|
628 |
-
|
629 |
-
gap: 12px !important;
|
630 |
-
align-items: end !important;
|
631 |
}
|
632 |
|
633 |
-
.
|
634 |
-
|
635 |
-
|
636 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
637 |
border-radius: 12px !important;
|
638 |
-
|
639 |
-
|
640 |
-
font-size: 14px !important;
|
641 |
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
|
|
|
|
|
642 |
}
|
643 |
|
644 |
-
.
|
645 |
-
|
646 |
-
|
647 |
-
|
|
|
648 |
outline: none !important;
|
649 |
}
|
650 |
|
651 |
-
/*
|
652 |
-
.
|
|
|
|
|
653 |
border-radius: 12px;
|
654 |
-
padding:
|
655 |
-
margin:
|
656 |
-
|
657 |
-
font-weight: 500;
|
658 |
text-align: center;
|
|
|
659 |
backdrop-filter: blur(10px);
|
|
|
|
|
|
|
|
|
660 |
}
|
661 |
|
662 |
-
|
663 |
-
|
664 |
-
|
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 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
|
|
678 |
}
|
679 |
|
680 |
-
/*
|
681 |
-
.
|
682 |
-
|
|
|
683 |
}
|
684 |
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
}
|
691 |
|
692 |
-
.
|
693 |
-
|
694 |
-
|
695 |
-
|
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 |
-
.
|
705 |
-
background: rgba(255,
|
706 |
-
|
707 |
-
|
|
|
708 |
}
|
709 |
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
|
|
|
|
714 |
}
|
715 |
|
716 |
-
|
717 |
-
|
718 |
-
|
|
|
|
|
|
|
|
|
719 |
}
|
720 |
|
721 |
-
|
722 |
-
|
723 |
-
|
|
|
724 |
}
|
725 |
|
726 |
-
|
727 |
-
|
728 |
}
|
729 |
|
730 |
/* Responsive design */
|
731 |
@media (max-width: 768px) {
|
732 |
-
.
|
733 |
-
|
734 |
-
padding: 16px;
|
735 |
-
gap: 16px;
|
736 |
}
|
737 |
|
738 |
-
.
|
739 |
-
|
740 |
}
|
741 |
|
742 |
-
.
|
743 |
-
|
744 |
}
|
745 |
|
746 |
-
.
|
747 |
-
|
|
|
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 |
-
#
|
781 |
-
with gr.
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
""")
|
790 |
|
791 |
-
|
792 |
-
|
|
|
|
|
|
|
793 |
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
""
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
811 |
show_label=False,
|
812 |
-
|
813 |
)
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
"
|
819 |
-
elem_classes=["primary-button"],
|
820 |
-
size="lg"
|
821 |
)
|
822 |
|
823 |
-
#
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
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 |
-
)
|
869 |
|
870 |
-
# State
|
871 |
doc_processed = gr.State(False)
|
872 |
|
873 |
# Event handlers
|
@@ -877,8 +942,8 @@ def create_interface():
|
|
877 |
|
878 |
# Show processing indicator
|
879 |
processing_html = f"""
|
880 |
-
<div class="
|
881 |
-
Processing {len(files)} documents... Please wait.
|
882 |
</div>
|
883 |
"""
|
884 |
|
@@ -886,29 +951,36 @@ def create_interface():
|
|
886 |
try:
|
887 |
result = coordinator_agent.process_files(files)
|
888 |
|
889 |
-
# Wait for processing
|
890 |
import time
|
891 |
time.sleep(3)
|
892 |
|
893 |
success_html = """
|
894 |
-
<div
|
895 |
-
|
|
|
|
|
|
|
896 |
</div>
|
897 |
"""
|
898 |
return gr.update(value=success_html, visible=True), True
|
899 |
|
900 |
except Exception as e:
|
901 |
error_html = f"""
|
902 |
-
<div
|
903 |
-
|
|
|
|
|
|
|
904 |
</div>
|
905 |
"""
|
906 |
return gr.update(value=error_html, visible=True), False
|
907 |
|
908 |
def respond(message, history, doc_ready):
|
909 |
if not doc_ready:
|
|
|
910 |
history.append({"role": "user", "content": message})
|
911 |
-
history.append({"role": "assistant", "content": "Please upload and process documents first."})
|
912 |
return history, ""
|
913 |
|
914 |
if not message.strip():
|
@@ -924,7 +996,7 @@ def create_interface():
|
|
924 |
history[-1]["content"] += token
|
925 |
yield history, ""
|
926 |
except Exception as e:
|
927 |
-
history[-1]["content"] = f"Error: {str(e)}"
|
928 |
yield history, ""
|
929 |
|
930 |
# Event bindings
|
|
|
419 |
coordinator_agent = CoordinatorAgent(message_bus)
|
420 |
|
421 |
def create_interface():
|
422 |
+
"""Create enhanced ChatGPT-style Gradio interface with glowing effects"""
|
423 |
|
424 |
with gr.Blocks(
|
425 |
+
theme=gr.themes.Base(),
|
426 |
css="""
|
427 |
+
/* Import Google Fonts for better typography */
|
428 |
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
|
429 |
+
|
430 |
+
/* Dark theme styling with enhanced visuals */
|
431 |
.gradio-container {
|
432 |
+
background: linear-gradient(135deg, #0a0a0a 0%, #1a1a2e 50%, #16213e 100%) !important;
|
433 |
+
color: #ffffff !important;
|
434 |
+
height: 100vh !important;
|
435 |
+
max-width: none !important;
|
436 |
+
padding: 0 !important;
|
437 |
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
|
438 |
+
}
|
439 |
+
|
440 |
+
/* Main container with animated background */
|
441 |
+
.main-container {
|
442 |
+
display: flex;
|
443 |
+
flex-direction: column;
|
444 |
+
height: 100vh;
|
445 |
+
background:
|
446 |
+
radial-gradient(circle at 20% 50%, rgba(255, 193, 7, 0.05) 0%, transparent 50%),
|
447 |
+
radial-gradient(circle at 80% 20%, rgba(0, 123, 255, 0.05) 0%, transparent 50%),
|
448 |
+
radial-gradient(circle at 40% 80%, rgba(255, 87, 34, 0.03) 0%, transparent 50%),
|
449 |
+
linear-gradient(135deg, #0a0a0a 0%, #1a1a2e 50%, #16213e 100%);
|
450 |
+
animation: backgroundShift 15s ease-in-out infinite alternate;
|
451 |
+
}
|
452 |
+
|
453 |
+
@keyframes backgroundShift {
|
454 |
+
0% { filter: hue-rotate(0deg); }
|
455 |
+
100% { filter: hue-rotate(10deg); }
|
456 |
}
|
457 |
|
458 |
+
/* Enhanced Header with glow */
|
459 |
+
.header {
|
460 |
+
background: rgba(255, 193, 7, 0.08);
|
461 |
+
border-bottom: 2px solid transparent;
|
462 |
+
border-image: linear-gradient(90deg, rgba(255, 193, 7, 0.5), rgba(0, 123, 255, 0.3)) 1;
|
463 |
+
padding: 1.5rem 2rem;
|
464 |
backdrop-filter: blur(20px);
|
465 |
+
box-shadow:
|
466 |
+
0 4px 20px rgba(255, 193, 7, 0.1),
|
467 |
+
inset 0 1px 0 rgba(255, 255, 255, 0.1);
|
468 |
+
position: relative;
|
|
|
469 |
overflow: hidden;
|
470 |
}
|
471 |
|
472 |
+
.header::before {
|
473 |
+
content: '';
|
474 |
+
position: absolute;
|
475 |
+
top: 0;
|
476 |
+
left: -100%;
|
477 |
+
width: 100%;
|
478 |
+
height: 100%;
|
479 |
+
background: linear-gradient(90deg, transparent, rgba(255, 193, 7, 0.1), transparent);
|
480 |
+
animation: shimmer 3s ease-in-out infinite;
|
481 |
+
}
|
482 |
+
|
483 |
+
@keyframes shimmer {
|
484 |
+
0% { left: -100%; }
|
485 |
+
100% { left: 100%; }
|
486 |
}
|
487 |
|
488 |
+
.header h1 {
|
489 |
+
color: #ffc107;
|
490 |
+
margin: 0;
|
491 |
+
font-size: 2rem;
|
492 |
font-weight: 700;
|
493 |
+
text-shadow:
|
494 |
+
0 0 10px rgba(255, 193, 7, 0.3),
|
495 |
+
0 0 20px rgba(255, 193, 7, 0.2);
|
|
|
|
|
496 |
letter-spacing: -0.02em;
|
497 |
}
|
498 |
|
499 |
+
.header p {
|
500 |
+
color: #e0e0e0;
|
501 |
+
margin: 0.5rem 0 0 0;
|
502 |
+
font-size: 1rem;
|
503 |
font-weight: 400;
|
504 |
+
opacity: 0.9;
|
|
|
505 |
}
|
506 |
|
507 |
+
/* Enhanced Chat container */
|
508 |
+
.chat-container {
|
509 |
+
flex: 1;
|
510 |
display: flex;
|
511 |
+
flex-direction: column;
|
512 |
+
max-width: 1200px;
|
513 |
+
margin: 0 auto;
|
514 |
+
width: 100%;
|
515 |
+
padding: 2rem;
|
516 |
+
height: calc(100vh - 200px) !important;
|
517 |
+
gap: 1.5rem;
|
518 |
}
|
519 |
|
520 |
+
/* Enhanced Chatbot with glow effect */
|
521 |
+
.gradio-chatbot {
|
522 |
+
height: 400px !important;
|
523 |
+
max-height: 400px !important;
|
524 |
+
background: rgba(45, 45, 45, 0.4) !important;
|
525 |
+
border: 2px solid rgba(255, 193, 7, 0.2) !important;
|
526 |
+
border-radius: 20px !important;
|
527 |
+
margin-bottom: 1rem;
|
528 |
+
overflow-y: auto !important;
|
529 |
+
box-shadow:
|
530 |
+
0 0 30px rgba(255, 193, 7, 0.15),
|
531 |
+
0 8px 32px rgba(0, 0, 0, 0.3),
|
532 |
+
inset 0 1px 0 rgba(255, 255, 255, 0.05) !important;
|
533 |
+
backdrop-filter: blur(20px) !important;
|
534 |
+
position: relative;
|
535 |
+
animation: chatGlow 4s ease-in-out infinite alternate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
536 |
}
|
537 |
|
538 |
+
@keyframes chatGlow {
|
539 |
+
0% {
|
540 |
+
box-shadow:
|
541 |
+
0 0 30px rgba(255, 193, 7, 0.15),
|
542 |
+
0 8px 32px rgba(0, 0, 0, 0.3),
|
543 |
+
inset 0 1px 0 rgba(255, 255, 255, 0.05);
|
544 |
+
}
|
545 |
+
100% {
|
546 |
+
box-shadow:
|
547 |
+
0 0 40px rgba(255, 193, 7, 0.25),
|
548 |
+
0 12px 40px rgba(0, 0, 0, 0.4),
|
549 |
+
inset 0 1px 0 rgba(255, 255, 255, 0.08);
|
550 |
+
}
|
551 |
}
|
552 |
|
553 |
+
/* Enhanced chat messages */
|
554 |
+
.message {
|
555 |
+
background: rgba(255, 255, 255, 0.05) !important;
|
556 |
+
border-radius: 16px !important;
|
557 |
+
padding: 1rem 1.5rem !important;
|
558 |
+
margin: 0.75rem 0 !important;
|
559 |
+
border: 1px solid rgba(255, 255, 255, 0.1) !important;
|
560 |
+
backdrop-filter: blur(10px) !important;
|
561 |
+
font-size: 0.95rem !important;
|
562 |
+
line-height: 1.6 !important;
|
563 |
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1) !important;
|
564 |
+
transition: all 0.3s ease !important;
|
565 |
}
|
566 |
|
567 |
+
.message:hover {
|
568 |
+
transform: translateY(-1px) !important;
|
569 |
+
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15) !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
570 |
}
|
571 |
|
572 |
+
/* User message styling */
|
573 |
+
.message.user {
|
574 |
+
background: linear-gradient(135deg, rgba(255, 193, 7, 0.1), rgba(255, 193, 7, 0.05)) !important;
|
575 |
+
border-color: rgba(255, 193, 7, 0.2) !important;
|
576 |
+
margin-left: 15% !important;
|
577 |
+
box-shadow:
|
578 |
+
0 2px 10px rgba(255, 193, 7, 0.1),
|
579 |
+
inset 0 1px 0 rgba(255, 255, 255, 0.05) !important;
|
580 |
}
|
581 |
|
582 |
+
/* Assistant message styling */
|
583 |
+
.message.assistant {
|
584 |
+
background: linear-gradient(135deg, rgba(0, 123, 255, 0.08), rgba(0, 123, 255, 0.04)) !important;
|
585 |
+
border-color: rgba(0, 123, 255, 0.2) !important;
|
586 |
+
margin-right: 15% !important;
|
587 |
+
box-shadow:
|
588 |
+
0 2px 10px rgba(0, 123, 255, 0.1),
|
589 |
+
inset 0 1px 0 rgba(255, 255, 255, 0.05) !important;
|
|
|
|
|
|
|
|
|
590 |
}
|
591 |
|
592 |
+
/* Enhanced Input area with glow */
|
593 |
+
.input-area {
|
594 |
+
background: rgba(45, 45, 45, 0.6);
|
595 |
+
border-radius: 20px;
|
596 |
+
padding: 1.5rem;
|
597 |
+
border: 2px solid rgba(255, 193, 7, 0.2);
|
598 |
+
backdrop-filter: blur(20px);
|
599 |
+
position: sticky;
|
600 |
+
bottom: 0;
|
601 |
+
box-shadow:
|
602 |
+
0 0 25px rgba(255, 193, 7, 0.1),
|
603 |
+
0 8px 32px rgba(0, 0, 0, 0.2),
|
604 |
+
inset 0 1px 0 rgba(255, 255, 255, 0.05);
|
605 |
+
animation: inputGlow 3s ease-in-out infinite alternate;
|
606 |
}
|
607 |
|
608 |
+
@keyframes inputGlow {
|
609 |
+
0% {
|
610 |
+
box-shadow:
|
611 |
+
0 0 25px rgba(255, 193, 7, 0.1),
|
612 |
+
0 8px 32px rgba(0, 0, 0, 0.2),
|
613 |
+
inset 0 1px 0 rgba(255, 255, 255, 0.05);
|
614 |
+
}
|
615 |
+
100% {
|
616 |
+
box-shadow:
|
617 |
+
0 0 35px rgba(255, 193, 7, 0.2),
|
618 |
+
0 12px 40px rgba(0, 0, 0, 0.3),
|
619 |
+
inset 0 1px 0 rgba(255, 255, 255, 0.08);
|
620 |
+
}
|
621 |
}
|
622 |
|
623 |
+
/* Enhanced File upload area */
|
624 |
+
.upload-area {
|
625 |
+
background: linear-gradient(135deg, rgba(255, 193, 7, 0.08), rgba(255, 193, 7, 0.04)) !important;
|
626 |
+
border: 2px dashed rgba(255, 193, 7, 0.4) !important;
|
627 |
+
border-radius: 16px !important;
|
628 |
+
padding: 1.5rem !important;
|
629 |
+
margin-bottom: 1.5rem !important;
|
630 |
+
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1) !important;
|
631 |
+
backdrop-filter: blur(10px) !important;
|
632 |
+
box-shadow:
|
633 |
+
0 0 20px rgba(255, 193, 7, 0.05),
|
634 |
+
inset 0 1px 0 rgba(255, 255, 255, 0.05) !important;
|
635 |
}
|
636 |
|
637 |
+
.upload-area:hover {
|
638 |
+
background: linear-gradient(135deg, rgba(255, 193, 7, 0.12), rgba(255, 193, 7, 0.06)) !important;
|
639 |
+
border-color: rgba(255, 193, 7, 0.6) !important;
|
640 |
+
box-shadow:
|
641 |
+
0 0 30px rgba(255, 193, 7, 0.15),
|
642 |
+
inset 0 1px 0 rgba(255, 255, 255, 0.08) !important;
|
643 |
+
transform: translateY(-2px) !important;
|
644 |
}
|
645 |
|
646 |
+
/* Sidebar styling */
|
647 |
+
.sidebar {
|
648 |
+
background: rgba(30, 30, 30, 0.6) !important;
|
649 |
+
border-right: 2px solid rgba(255, 193, 7, 0.1) !important;
|
650 |
+
backdrop-filter: blur(15px) !important;
|
651 |
+
box-shadow:
|
652 |
+
inset -1px 0 0 rgba(255, 255, 255, 0.05),
|
653 |
+
4px 0 20px rgba(0, 0, 0, 0.1) !important;
|
654 |
+
}
|
655 |
+
|
656 |
+
/* Enhanced buttons with glow effects */
|
657 |
+
.send-btn {
|
658 |
+
background: linear-gradient(135deg, #ffc107 0%, #ff8f00 100%) !important;
|
659 |
+
color: #000000 !important;
|
660 |
border: none !important;
|
661 |
+
border-radius: 12px !important;
|
662 |
+
font-weight: 600 !important;
|
663 |
+
min-height: 48px !important;
|
664 |
+
font-size: 0.95rem !important;
|
665 |
+
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
|
666 |
+
box-shadow:
|
667 |
+
0 4px 15px rgba(255, 193, 7, 0.3),
|
668 |
+
0 0 20px rgba(255, 193, 7, 0.2) !important;
|
669 |
+
position: relative;
|
670 |
+
overflow: hidden;
|
671 |
}
|
672 |
|
673 |
+
.send-btn::before {
|
674 |
+
content: '';
|
675 |
+
position: absolute;
|
676 |
+
top: 0;
|
677 |
+
left: -100%;
|
678 |
+
width: 100%;
|
679 |
+
height: 100%;
|
680 |
+
background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
|
681 |
+
transition: left 0.5s;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
682 |
}
|
683 |
|
684 |
+
.send-btn:hover::before {
|
685 |
+
left: 100%;
|
|
|
|
|
686 |
}
|
687 |
|
688 |
+
.send-btn:hover {
|
689 |
+
transform: translateY(-2px) !important;
|
690 |
+
box-shadow:
|
691 |
+
0 8px 25px rgba(255, 193, 7, 0.4),
|
692 |
+
0 0 30px rgba(255, 193, 7, 0.3) !important;
|
693 |
+
}
|
694 |
+
|
695 |
+
.primary-btn {
|
696 |
+
background: linear-gradient(135deg, #ffc107 0%, #ff8f00 100%) !important;
|
697 |
+
color: #000000 !important;
|
698 |
+
border: none !important;
|
699 |
+
border-radius: 12px !important;
|
700 |
+
font-weight: 600 !important;
|
701 |
+
padding: 0.75rem 1.5rem !important;
|
702 |
+
font-size: 0.95rem !important;
|
703 |
+
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
|
704 |
+
box-shadow:
|
705 |
+
0 4px 15px rgba(255, 193, 7, 0.3),
|
706 |
+
0 0 20px rgba(255, 193, 7, 0.2) !important;
|
707 |
+
}
|
708 |
+
|
709 |
+
.primary-btn:hover {
|
710 |
+
transform: translateY(-2px) !important;
|
711 |
+
box-shadow:
|
712 |
+
0 8px 25px rgba(255, 193, 7, 0.4),
|
713 |
+
0 0 30px rgba(255, 193, 7, 0.3) !important;
|
714 |
+
}
|
715 |
+
|
716 |
+
/* Enhanced Text inputs with glow */
|
717 |
+
.gradio-textbox input, .gradio-textbox textarea {
|
718 |
+
background: rgba(45, 45, 45, 0.8) !important;
|
719 |
+
color: #ffffff !important;
|
720 |
+
border: 2px solid rgba(255, 193, 7, 0.2) !important;
|
721 |
border-radius: 12px !important;
|
722 |
+
font-size: 0.95rem !important;
|
723 |
+
padding: 0.75rem 1rem !important;
|
|
|
724 |
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
|
725 |
+
backdrop-filter: blur(10px) !important;
|
726 |
+
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1) !important;
|
727 |
}
|
728 |
|
729 |
+
.gradio-textbox input:focus, .gradio-textbox textarea:focus {
|
730 |
+
border-color: rgba(255, 193, 7, 0.5) !important;
|
731 |
+
box-shadow:
|
732 |
+
0 0 20px rgba(255, 193, 7, 0.2),
|
733 |
+
inset 0 2px 4px rgba(0, 0, 0, 0.1) !important;
|
734 |
outline: none !important;
|
735 |
}
|
736 |
|
737 |
+
/* Enhanced Processing indicator */
|
738 |
+
.processing-indicator {
|
739 |
+
background: linear-gradient(135deg, rgba(255, 193, 7, 0.15), rgba(255, 193, 7, 0.08));
|
740 |
+
border: 2px solid rgba(255, 193, 7, 0.3);
|
741 |
border-radius: 12px;
|
742 |
+
padding: 1rem 1.5rem;
|
743 |
+
margin: 1rem 0;
|
744 |
+
color: #ffc107;
|
|
|
745 |
text-align: center;
|
746 |
+
font-weight: 500;
|
747 |
backdrop-filter: blur(10px);
|
748 |
+
box-shadow:
|
749 |
+
0 0 25px rgba(255, 193, 7, 0.1),
|
750 |
+
inset 0 1px 0 rgba(255, 255, 255, 0.1);
|
751 |
+
animation: processingPulse 2s ease-in-out infinite;
|
752 |
}
|
753 |
|
754 |
+
@keyframes processingPulse {
|
755 |
+
0%, 100% { opacity: 1; }
|
756 |
+
50% { opacity: 0.8; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
757 |
}
|
758 |
|
759 |
+
/* Enhanced Input row styling */
|
760 |
+
.input-row {
|
761 |
+
display: flex !important;
|
762 |
+
gap: 12px !important;
|
763 |
+
align-items: end !important;
|
764 |
}
|
765 |
|
766 |
+
/* Message input */
|
767 |
+
.message-input {
|
768 |
+
flex: 1 !important;
|
769 |
+
min-height: 48px !important;
|
770 |
}
|
771 |
|
772 |
+
/* Markdown content styling */
|
773 |
+
.markdown-content {
|
774 |
+
color: #e0e0e0 !important;
|
775 |
+
line-height: 1.6 !important;
|
776 |
+
font-size: 0.95rem !important;
|
777 |
}
|
778 |
|
779 |
+
.markdown-content h1, .markdown-content h2, .markdown-content h3 {
|
780 |
+
color: #ffc107 !important;
|
781 |
+
margin-top: 1.5rem !important;
|
782 |
+
margin-bottom: 0.5rem !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
783 |
}
|
784 |
|
785 |
+
.markdown-content code {
|
786 |
+
background: rgba(255, 193, 7, 0.1) !important;
|
787 |
+
color: #ffc107 !important;
|
788 |
+
padding: 0.2rem 0.4rem !important;
|
789 |
+
border-radius: 4px !important;
|
790 |
}
|
791 |
|
792 |
+
.markdown-content pre {
|
793 |
+
background: rgba(0, 0, 0, 0.3) !important;
|
794 |
+
border: 1px solid rgba(255, 193, 7, 0.2) !important;
|
795 |
+
border-radius: 8px !important;
|
796 |
+
padding: 1rem !important;
|
797 |
+
margin: 1rem 0 !important;
|
798 |
}
|
799 |
|
800 |
+
/* Examples styling */
|
801 |
+
.examples {
|
802 |
+
background: rgba(45, 45, 45, 0.3) !important;
|
803 |
+
border-radius: 12px !important;
|
804 |
+
padding: 1rem !important;
|
805 |
+
border: 1px solid rgba(255, 193, 7, 0.1) !important;
|
806 |
+
backdrop-filter: blur(10px) !important;
|
807 |
}
|
808 |
|
809 |
+
/* Loading animation */
|
810 |
+
@keyframes loading {
|
811 |
+
0% { transform: rotate(0deg); }
|
812 |
+
100% { transform: rotate(360deg); }
|
813 |
}
|
814 |
|
815 |
+
.loading {
|
816 |
+
animation: loading 2s linear infinite;
|
817 |
}
|
818 |
|
819 |
/* Responsive design */
|
820 |
@media (max-width: 768px) {
|
821 |
+
.chat-container {
|
822 |
+
padding: 1rem;
|
|
|
|
|
823 |
}
|
824 |
|
825 |
+
.header h1 {
|
826 |
+
font-size: 1.5rem;
|
827 |
}
|
828 |
|
829 |
+
.gradio-chatbot {
|
830 |
+
height: 300px !important;
|
831 |
}
|
832 |
|
833 |
+
.input-row {
|
834 |
+
flex-direction: column !important;
|
835 |
+
gap: 8px !important;
|
836 |
}
|
837 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
838 |
""",
|
839 |
title="Agentic RAG Assistant"
|
840 |
) as iface:
|
841 |
|
842 |
+
# Header
|
843 |
+
with gr.Row():
|
844 |
+
with gr.Column():
|
845 |
+
gr.HTML("""
|
846 |
+
<div class="header">
|
847 |
+
<h1>β¨ Agentic RAG Assistant</h1>
|
848 |
+
<p>π€ Upload documents and ask questions - powered by Multi-Agent Architecture with streaming responses</p>
|
849 |
+
</div>
|
850 |
+
""")
|
|
|
851 |
|
852 |
+
# Main layout with sidebar and chat
|
853 |
+
with gr.Row():
|
854 |
+
# Left sidebar for file upload
|
855 |
+
with gr.Column(scale=1, elem_classes=["sidebar"]):
|
856 |
+
gr.Markdown("### π Document Upload", elem_classes=["markdown-content"])
|
857 |
|
858 |
+
file_upload = gr.File(
|
859 |
+
file_count="multiple",
|
860 |
+
file_types=[".pdf", ".pptx", ".csv", ".docx", ".txt", ".md"],
|
861 |
+
label="π Upload Documents",
|
862 |
+
elem_classes=["upload-area"]
|
863 |
+
)
|
864 |
+
|
865 |
+
processing_status = gr.HTML(visible=False)
|
866 |
+
|
867 |
+
process_btn = gr.Button(
|
868 |
+
"π Process Documents",
|
869 |
+
variant="primary",
|
870 |
+
elem_classes=["primary-btn"]
|
871 |
+
)
|
872 |
+
|
873 |
+
gr.Markdown("""
|
874 |
+
### β‘ Architecture
|
875 |
+
|
876 |
+
**Multi-Agent System:**
|
877 |
+
- π **IngestionAgent**: Document parsing
|
878 |
+
- π **RetrievalAgent**: Semantic search
|
879 |
+
- π€ **LLMAgent**: Response generation
|
880 |
+
- π― **CoordinatorAgent**: Workflow orchestration
|
881 |
+
|
882 |
+
**β¨ Features:**
|
883 |
+
- π Streaming responses
|
884 |
+
- π Multi-format support
|
885 |
+
- π§ Context-aware answers
|
886 |
+
- π₯ Real-time processing
|
887 |
+
""", elem_classes=["markdown-content"])
|
888 |
+
|
889 |
+
# Right side - Chat interface
|
890 |
+
with gr.Column(scale=2):
|
891 |
+
gr.Markdown("### π¬ Chat Interface", elem_classes=["markdown-content"])
|
892 |
+
|
893 |
+
# Chatbot with enhanced styling
|
894 |
+
chatbot = gr.Chatbot(
|
895 |
+
height=400,
|
896 |
+
elem_classes=["gradio-chatbot"],
|
897 |
+
show_copy_button=True,
|
898 |
+
type="messages",
|
899 |
+
placeholder="π Upload documents first, then start chatting! Ask me anything about your documents.",
|
900 |
+
avatar_images=("π€", "π€")
|
901 |
+
)
|
902 |
+
|
903 |
+
# Input area with improved layout
|
904 |
+
with gr.Row(elem_classes=["input-row"]):
|
905 |
+
msg_input = gr.Textbox(
|
906 |
+
placeholder="π Ask about your documents...",
|
907 |
+
label="Message",
|
908 |
+
scale=4,
|
909 |
+
elem_classes=["message-input"],
|
910 |
show_label=False,
|
911 |
+
autofocus=True
|
912 |
)
|
913 |
+
send_btn = gr.Button(
|
914 |
+
"π Send",
|
915 |
+
scale=1,
|
916 |
+
elem_classes=["send-btn"],
|
917 |
+
size="sm"
|
|
|
|
|
918 |
)
|
919 |
|
920 |
+
# Enhanced Examples
|
921 |
+
gr.Examples(
|
922 |
+
examples=[
|
923 |
+
"π What are the main topics discussed?",
|
924 |
+
"π Summarize the key findings",
|
925 |
+
"π What metrics are mentioned?",
|
926 |
+
"π‘ What are the recommendations?",
|
927 |
+
"π Find specific information about...",
|
928 |
+
"π Create a summary of the content"
|
929 |
+
],
|
930 |
+
inputs=msg_input,
|
931 |
+
label="π‘ Example Questions",
|
932 |
+
elem_classes=["examples"]
|
933 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
934 |
|
935 |
+
# State to track document processing
|
936 |
doc_processed = gr.State(False)
|
937 |
|
938 |
# Event handlers
|
|
|
942 |
|
943 |
# Show processing indicator
|
944 |
processing_html = f"""
|
945 |
+
<div class="processing-indicator">
|
946 |
+
π Processing {len(files)} documents... Please wait while we analyze your content.
|
947 |
</div>
|
948 |
"""
|
949 |
|
|
|
951 |
try:
|
952 |
result = coordinator_agent.process_files(files)
|
953 |
|
954 |
+
# Wait a moment for processing to complete
|
955 |
import time
|
956 |
time.sleep(3)
|
957 |
|
958 |
success_html = """
|
959 |
+
<div style="background: linear-gradient(135deg, rgba(76, 175, 80, 0.15), rgba(76, 175, 80, 0.08));
|
960 |
+
border: 2px solid rgba(76, 175, 80, 0.3); border-radius: 12px; padding: 1rem 1.5rem;
|
961 |
+
color: #4caf50; text-align: center; backdrop-filter: blur(10px);
|
962 |
+
box-shadow: 0 0 20px rgba(76, 175, 80, 0.1);">
|
963 |
+
β
Documents processed successfully! You can now ask questions about your content.
|
964 |
</div>
|
965 |
"""
|
966 |
return gr.update(value=success_html, visible=True), True
|
967 |
|
968 |
except Exception as e:
|
969 |
error_html = f"""
|
970 |
+
<div style="background: linear-gradient(135deg, rgba(244, 67, 54, 0.15), rgba(244, 67, 54, 0.08));
|
971 |
+
border: 2px solid rgba(244, 67, 54, 0.3); border-radius: 12px; padding: 1rem 1.5rem;
|
972 |
+
color: #f44336; text-align: center; backdrop-filter: blur(10px);
|
973 |
+
box-shadow: 0 0 20px rgba(244, 67, 54, 0.1);">
|
974 |
+
β Error processing documents: {str(e)}
|
975 |
</div>
|
976 |
"""
|
977 |
return gr.update(value=error_html, visible=True), False
|
978 |
|
979 |
def respond(message, history, doc_ready):
|
980 |
if not doc_ready:
|
981 |
+
# Show error message
|
982 |
history.append({"role": "user", "content": message})
|
983 |
+
history.append({"role": "assistant", "content": "β οΈ Please upload and process documents first before asking questions."})
|
984 |
return history, ""
|
985 |
|
986 |
if not message.strip():
|
|
|
996 |
history[-1]["content"] += token
|
997 |
yield history, ""
|
998 |
except Exception as e:
|
999 |
+
history[-1]["content"] = f"β Error generating response: {str(e)}"
|
1000 |
yield history, ""
|
1001 |
|
1002 |
# Event bindings
|