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