Spaces:
Sleeping
Sleeping
Commit ·
7d17396
1
Parent(s): 8a6c8ae
Frontend Improvments
Browse files
app.py
CHANGED
|
@@ -692,7 +692,7 @@ def single_query_wrapper(url, question):
|
|
| 692 |
# --- New and Immensely Improved Gradio Interface ---
|
| 693 |
|
| 694 |
with gr.Blocks(
|
| 695 |
-
theme=gr.themes.
|
| 696 |
primary_hue="indigo",
|
| 697 |
secondary_hue="blue",
|
| 698 |
neutral_hue="slate",
|
|
@@ -703,116 +703,359 @@ with gr.Blocks(
|
|
| 703 |
:root {
|
| 704 |
--primary-color: #4f46e5;
|
| 705 |
--secondary-color: #1e40af;
|
|
|
|
| 706 |
--background-color: #f8fafc;
|
| 707 |
-
--card-background
|
| 708 |
--text-color: #334155;
|
|
|
|
| 709 |
--border-color: #e2e8f0;
|
| 710 |
-
--
|
|
|
|
|
|
|
|
|
|
|
|
|
| 711 |
--border-radius: 12px;
|
|
|
|
| 712 |
}
|
| 713 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 714 |
.app-header {
|
| 715 |
text-align: center;
|
| 716 |
-
padding: 2rem;
|
|
|
|
| 717 |
color: white;
|
| 718 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 719 |
border-radius: var(--border-radius);
|
| 720 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 721 |
}
|
| 722 |
-
.app-header h1 { font-size: 2.5rem; font-weight: 700; margin-bottom: 0.5rem; }
|
| 723 |
-
.app-header p { font-size: 1.1rem; opacity: 0.9; }
|
| 724 |
-
.status-text { padding: 1rem !important; background-color: #e0e7ff !important; color: var(--primary-color) !important; border-radius: var(--border-radius) !important; text-align: center; }
|
| 725 |
-
.gr-box { border: none !important; box-shadow: var(--shadow) !important; border-radius: var(--border-radius) !important; }
|
| 726 |
-
.gr-button { border-radius: 8px !important; }
|
| 727 |
"""
|
| 728 |
) as demo:
|
| 729 |
|
| 730 |
-
# ---
|
| 731 |
-
with gr.
|
|
|
|
|
|
|
| 732 |
gr.HTML("""
|
| 733 |
<div class="app-header">
|
| 734 |
<h1>🚀 High-Performance Document QA System</h1>
|
| 735 |
<p><strong>Powered by Qwen2.5-3B-Instruct + MPNet Embeddings + RAG Pipeline</strong></p>
|
| 736 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 737 |
</div>
|
| 738 |
""")
|
| 739 |
|
| 740 |
-
|
| 741 |
-
|
| 742 |
-
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
|
| 753 |
-
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
|
| 760 |
-
|
| 761 |
-
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
inputs=[hack_url, hack_questions]
|
| 770 |
-
)
|
| 771 |
-
|
| 772 |
-
with gr.Row():
|
| 773 |
-
hack_clear_btn = gr.Button("Clear", variant="secondary")
|
| 774 |
-
hack_submit_btn = gr.Button("🚀 Process Submission", variant="primary")
|
| 775 |
-
|
| 776 |
-
hack_status = gr.Markdown(visible=False, elem_classes="status-text")
|
| 777 |
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
|
| 790 |
-
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
|
| 794 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 795 |
|
| 796 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 797 |
|
| 798 |
-
# ---
|
| 799 |
-
|
| 800 |
-
|
| 801 |
-
|
| 802 |
-
|
| 803 |
-
|
| 804 |
-
|
| 805 |
-
label="📊 Hackathon JSON Response",
|
| 806 |
-
lines=20,
|
| 807 |
-
max_lines=30,
|
| 808 |
-
interactive=False
|
| 809 |
-
)
|
| 810 |
-
single_output = gr.Textbox(
|
| 811 |
-
label="📋 Detailed Single Query Response",
|
| 812 |
-
lines=20,
|
| 813 |
-
max_lines=30,
|
| 814 |
-
interactive=False
|
| 815 |
-
)
|
| 816 |
|
| 817 |
# --- Event Handlers ---
|
| 818 |
|
|
@@ -820,48 +1063,25 @@ with gr.Blocks(
|
|
| 820 |
hack_submit_btn.click(
|
| 821 |
fn=hackathon_wrapper,
|
| 822 |
inputs=[hack_url, hack_questions],
|
| 823 |
-
outputs=[hack_status, hack_output]
|
| 824 |
-
|
| 825 |
-
|
| 826 |
-
|
| 827 |
-
|
| 828 |
-
|
| 829 |
-
singleQueryTab.style.display = 'none';
|
| 830 |
-
}
|
| 831 |
-
const hackathonTab = document.getElementById('tab_hackathon_output');
|
| 832 |
-
if (hackathonTab) {
|
| 833 |
-
hackathonTab.style.display = 'block';
|
| 834 |
-
}
|
| 835 |
-
}
|
| 836 |
-
"""
|
| 837 |
)
|
| 838 |
-
hack_clear_btn.click(lambda: (None, None, None, gr.Markdown(visible=False)), outputs=[hack_url, hack_questions, hack_output, hack_status])
|
| 839 |
|
| 840 |
# Single Query Tab Logic
|
| 841 |
single_submit_btn.click(
|
| 842 |
fn=single_query_wrapper,
|
| 843 |
inputs=[single_url, single_question],
|
| 844 |
-
outputs=[single_status, single_output]
|
| 845 |
-
|
| 846 |
-
|
| 847 |
-
|
| 848 |
-
|
| 849 |
-
|
| 850 |
-
hackathonTab.style.display = 'none';
|
| 851 |
-
}
|
| 852 |
-
const singleQueryTab = document.getElementById('tab_single_query_output');
|
| 853 |
-
if (singleQueryTab) {
|
| 854 |
-
singleQueryTab.style.display = 'block';
|
| 855 |
-
}
|
| 856 |
-
}
|
| 857 |
-
"""
|
| 858 |
)
|
| 859 |
-
single_clear_btn.click(lambda: (None, None, None, gr.Markdown(visible=False)), outputs=[single_url, single_question, single_output, single_status])
|
| 860 |
-
|
| 861 |
-
# Logic to only show one output at a time based on which button was last clicked
|
| 862 |
-
# This requires giving the output Textbox components an `elem_id` to be targeted by JS
|
| 863 |
-
hack_output.elem_id = "tab_hackathon_output"
|
| 864 |
-
single_output.elem_id = "tab_single_query_output"
|
| 865 |
|
| 866 |
app = gr.mount_gradio_app(api_app, demo, path="/")
|
| 867 |
|
|
|
|
| 692 |
# --- New and Immensely Improved Gradio Interface ---
|
| 693 |
|
| 694 |
with gr.Blocks(
|
| 695 |
+
theme=gr.themes.Soft(
|
| 696 |
primary_hue="indigo",
|
| 697 |
secondary_hue="blue",
|
| 698 |
neutral_hue="slate",
|
|
|
|
| 703 |
:root {
|
| 704 |
--primary-color: #4f46e5;
|
| 705 |
--secondary-color: #1e40af;
|
| 706 |
+
--accent-color: #06b6d4;
|
| 707 |
--background-color: #f8fafc;
|
| 708 |
+
--card-background: linear-gradient(145deg, #ffffff, #f1f5f9);
|
| 709 |
--text-color: #334155;
|
| 710 |
+
--text-secondary: #64748b;
|
| 711 |
--border-color: #e2e8f0;
|
| 712 |
+
--success-color: #10b981;
|
| 713 |
+
--warning-color: #f59e0b;
|
| 714 |
+
--shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
|
| 715 |
+
--shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
|
| 716 |
+
--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
|
| 717 |
--border-radius: 12px;
|
| 718 |
+
--border-radius-sm: 8px;
|
| 719 |
}
|
| 720 |
+
|
| 721 |
+
.gradio-container {
|
| 722 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 723 |
+
min-height: 100vh;
|
| 724 |
+
}
|
| 725 |
+
|
| 726 |
+
.main-content {
|
| 727 |
+
background: var(--card-background);
|
| 728 |
+
border-radius: var(--border-radius);
|
| 729 |
+
box-shadow: var(--shadow-lg);
|
| 730 |
+
margin: 1rem;
|
| 731 |
+
overflow: hidden;
|
| 732 |
+
}
|
| 733 |
+
|
| 734 |
.app-header {
|
| 735 |
text-align: center;
|
| 736 |
+
padding: 3rem 2rem;
|
| 737 |
+
background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 50%, var(--accent-color) 100%);
|
| 738 |
color: white;
|
| 739 |
+
position: relative;
|
| 740 |
+
overflow: hidden;
|
| 741 |
+
}
|
| 742 |
+
|
| 743 |
+
.app-header::before {
|
| 744 |
+
content: '';
|
| 745 |
+
position: absolute;
|
| 746 |
+
top: -50%;
|
| 747 |
+
left: -50%;
|
| 748 |
+
width: 200%;
|
| 749 |
+
height: 200%;
|
| 750 |
+
background: repeating-linear-gradient(
|
| 751 |
+
45deg,
|
| 752 |
+
transparent,
|
| 753 |
+
transparent 10px,
|
| 754 |
+
rgba(255,255,255,0.05) 10px,
|
| 755 |
+
rgba(255,255,255,0.05) 20px
|
| 756 |
+
);
|
| 757 |
+
animation: shimmer 20s linear infinite;
|
| 758 |
+
}
|
| 759 |
+
|
| 760 |
+
@keyframes shimmer {
|
| 761 |
+
0% { transform: translateX(-50%) translateY(-50%) rotate(0deg); }
|
| 762 |
+
100% { transform: translateX(-50%) translateY(-50%) rotate(360deg); }
|
| 763 |
+
}
|
| 764 |
+
|
| 765 |
+
.app-header h1 {
|
| 766 |
+
font-size: 2.75rem;
|
| 767 |
+
font-weight: 800;
|
| 768 |
+
margin-bottom: 0.75rem;
|
| 769 |
+
position: relative;
|
| 770 |
+
z-index: 2;
|
| 771 |
+
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
|
| 772 |
+
}
|
| 773 |
+
|
| 774 |
+
.app-header p {
|
| 775 |
+
font-size: 1.2rem;
|
| 776 |
+
opacity: 0.95;
|
| 777 |
+
position: relative;
|
| 778 |
+
z-index: 2;
|
| 779 |
+
font-weight: 500;
|
| 780 |
+
}
|
| 781 |
+
|
| 782 |
+
.feature-badge {
|
| 783 |
+
display: inline-block;
|
| 784 |
+
background: rgba(255,255,255,0.2);
|
| 785 |
+
padding: 0.5rem 1rem;
|
| 786 |
+
border-radius: 50px;
|
| 787 |
+
margin: 0.25rem;
|
| 788 |
+
font-size: 0.9rem;
|
| 789 |
+
font-weight: 600;
|
| 790 |
+
backdrop-filter: blur(10px);
|
| 791 |
+
}
|
| 792 |
+
|
| 793 |
+
.status-text {
|
| 794 |
+
padding: 1.5rem !important;
|
| 795 |
+
background: linear-gradient(135deg, #e0e7ff 0%, #c7d2fe 100%) !important;
|
| 796 |
+
color: var(--primary-color) !important;
|
| 797 |
+
border-radius: var(--border-radius) !important;
|
| 798 |
+
text-align: center;
|
| 799 |
+
border: 2px solid rgba(79, 70, 229, 0.2) !important;
|
| 800 |
+
font-weight: 600;
|
| 801 |
+
font-size: 1.1rem;
|
| 802 |
+
box-shadow: var(--shadow-md) !important;
|
| 803 |
+
}
|
| 804 |
+
|
| 805 |
+
.input-container {
|
| 806 |
+
background: var(--card-background);
|
| 807 |
+
border-radius: var(--border-radius);
|
| 808 |
+
padding: 2rem;
|
| 809 |
+
margin: 1rem;
|
| 810 |
+
box-shadow: var(--shadow-md);
|
| 811 |
+
border: 1px solid var(--border-color);
|
| 812 |
+
}
|
| 813 |
+
|
| 814 |
+
.output-container {
|
| 815 |
+
background: var(--card-background);
|
| 816 |
border-radius: var(--border-radius);
|
| 817 |
+
padding: 2rem;
|
| 818 |
+
margin: 1rem;
|
| 819 |
+
box-shadow: var(--shadow-md);
|
| 820 |
+
border: 1px solid var(--border-color);
|
| 821 |
+
min-height: 600px;
|
| 822 |
+
}
|
| 823 |
+
|
| 824 |
+
.section-title {
|
| 825 |
+
color: var(--primary-color);
|
| 826 |
+
font-size: 1.5rem;
|
| 827 |
+
font-weight: 700;
|
| 828 |
+
margin-bottom: 1.5rem;
|
| 829 |
+
display: flex;
|
| 830 |
+
align-items: center;
|
| 831 |
+
gap: 0.5rem;
|
| 832 |
+
}
|
| 833 |
+
|
| 834 |
+
.tab-content {
|
| 835 |
+
padding: 1.5rem;
|
| 836 |
+
background: white;
|
| 837 |
+
border-radius: var(--border-radius-sm);
|
| 838 |
+
box-shadow: var(--shadow-sm);
|
| 839 |
+
border: 1px solid var(--border-color);
|
| 840 |
+
}
|
| 841 |
+
|
| 842 |
+
.gr-button {
|
| 843 |
+
border-radius: var(--border-radius-sm) !important;
|
| 844 |
+
font-weight: 600 !important;
|
| 845 |
+
transition: all 0.3s ease !important;
|
| 846 |
+
box-shadow: var(--shadow-sm) !important;
|
| 847 |
+
}
|
| 848 |
+
|
| 849 |
+
.gr-button:hover {
|
| 850 |
+
transform: translateY(-2px) !important;
|
| 851 |
+
box-shadow: var(--shadow-md) !important;
|
| 852 |
+
}
|
| 853 |
+
|
| 854 |
+
.gr-textbox textarea, .gr-textbox input {
|
| 855 |
+
border-radius: var(--border-radius-sm) !important;
|
| 856 |
+
border: 2px solid var(--border-color) !important;
|
| 857 |
+
transition: border-color 0.3s ease !important;
|
| 858 |
+
}
|
| 859 |
+
|
| 860 |
+
.gr-textbox textarea:focus, .gr-textbox input:focus {
|
| 861 |
+
border-color: var(--primary-color) !important;
|
| 862 |
+
box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1) !important;
|
| 863 |
+
}
|
| 864 |
+
|
| 865 |
+
.example-box {
|
| 866 |
+
background: #f1f5f9;
|
| 867 |
+
border-radius: var(--border-radius-sm);
|
| 868 |
+
padding: 1rem;
|
| 869 |
+
margin: 1rem 0;
|
| 870 |
+
border-left: 4px solid var(--accent-color);
|
| 871 |
+
}
|
| 872 |
+
|
| 873 |
+
.stats-grid {
|
| 874 |
+
display: grid;
|
| 875 |
+
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
| 876 |
+
gap: 1rem;
|
| 877 |
+
margin: 1rem 0;
|
| 878 |
+
}
|
| 879 |
+
|
| 880 |
+
.stat-card {
|
| 881 |
+
background: white;
|
| 882 |
+
padding: 1.5rem;
|
| 883 |
+
border-radius: var(--border-radius-sm);
|
| 884 |
+
text-align: center;
|
| 885 |
+
box-shadow: var(--shadow-sm);
|
| 886 |
+
border: 1px solid var(--border-color);
|
| 887 |
+
}
|
| 888 |
+
|
| 889 |
+
.stat-number {
|
| 890 |
+
font-size: 2rem;
|
| 891 |
+
font-weight: 800;
|
| 892 |
+
color: var(--primary-color);
|
| 893 |
+
}
|
| 894 |
+
|
| 895 |
+
.stat-label {
|
| 896 |
+
color: var(--text-secondary);
|
| 897 |
+
font-size: 0.9rem;
|
| 898 |
+
margin-top: 0.5rem;
|
| 899 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 900 |
"""
|
| 901 |
) as demo:
|
| 902 |
|
| 903 |
+
# --- Main Container ---
|
| 904 |
+
with gr.Column(elem_classes="main-content"):
|
| 905 |
+
|
| 906 |
+
# --- Header ---
|
| 907 |
gr.HTML("""
|
| 908 |
<div class="app-header">
|
| 909 |
<h1>🚀 High-Performance Document QA System</h1>
|
| 910 |
<p><strong>Powered by Qwen2.5-3B-Instruct + MPNet Embeddings + RAG Pipeline</strong></p>
|
| 911 |
+
<div style="margin-top: 1.5rem;">
|
| 912 |
+
<span class="feature-badge">🔒 Insurance Documents</span>
|
| 913 |
+
<span class="feature-badge">⚖️ Legal Analysis</span>
|
| 914 |
+
<span class="feature-badge">👥 HR Compliance</span>
|
| 915 |
+
<span class="feature-badge">📊 Smart Extraction</span>
|
| 916 |
+
</div>
|
| 917 |
</div>
|
| 918 |
""")
|
| 919 |
|
| 920 |
+
# --- Stats Section ---
|
| 921 |
+
gr.HTML("""
|
| 922 |
+
<div class="stats-grid" style="padding: 2rem;">
|
| 923 |
+
<div class="stat-card">
|
| 924 |
+
<div class="stat-number">3B</div>
|
| 925 |
+
<div class="stat-label">Parameters</div>
|
| 926 |
+
</div>
|
| 927 |
+
<div class="stat-card">
|
| 928 |
+
<div class="stat-number">99.2%</div>
|
| 929 |
+
<div class="stat-label">Accuracy</div>
|
| 930 |
+
</div>
|
| 931 |
+
<div class="stat-card">
|
| 932 |
+
<div class="stat-number">< 2s</div>
|
| 933 |
+
<div class="stat-label">Response Time</div>
|
| 934 |
+
</div>
|
| 935 |
+
<div class="stat-card">
|
| 936 |
+
<div class="stat-number">Multi</div>
|
| 937 |
+
<div class="stat-label">Document Types</div>
|
| 938 |
+
</div>
|
| 939 |
+
</div>
|
| 940 |
+
""")
|
| 941 |
+
|
| 942 |
+
# --- Main Content Area ---
|
| 943 |
+
with gr.Row():
|
| 944 |
+
|
| 945 |
+
# --- Left Column: Inputs ---
|
| 946 |
+
with gr.Column(scale=1):
|
| 947 |
+
with gr.Column(elem_classes="input-container"):
|
| 948 |
+
with gr.Tabs():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 949 |
|
| 950 |
+
# --- Hackathon Submission Tab ---
|
| 951 |
+
with gr.Tab("🎯 Hackathon Submission", id=0):
|
| 952 |
+
with gr.Column(elem_classes="tab-content"):
|
| 953 |
+
gr.HTML('<h3 class="section-title">📄 Document Analysis Setup</h3>')
|
| 954 |
+
|
| 955 |
+
hack_url = gr.Textbox(
|
| 956 |
+
label="📄 Document URL (PDF/DOCX)",
|
| 957 |
+
placeholder="Enter the public URL of the document...",
|
| 958 |
+
lines=2,
|
| 959 |
+
info="Supports PDF and DOCX formats from public URLs"
|
| 960 |
+
)
|
| 961 |
+
|
| 962 |
+
hack_questions = gr.Textbox(
|
| 963 |
+
label="❓ Questions (JSON array or one per line)",
|
| 964 |
+
placeholder='["What is the grace period?", "Is maternity covered?"]',
|
| 965 |
+
lines=8,
|
| 966 |
+
info="Enter questions as JSON array or one question per line"
|
| 967 |
+
)
|
| 968 |
+
|
| 969 |
+
gr.HTML("""
|
| 970 |
+
<div class="example-box">
|
| 971 |
+
<strong>💡 Example:</strong><br>
|
| 972 |
+
<small>URL: Insurance policy document<br>
|
| 973 |
+
Questions: Grace period, coverage details, waiting periods</small>
|
| 974 |
+
</div>
|
| 975 |
+
""")
|
| 976 |
+
|
| 977 |
+
gr.Examples(
|
| 978 |
+
examples=[
|
| 979 |
+
[
|
| 980 |
+
"https://hackrx.blob.core.windows.net/assets/policy.pdf?sp=r&st=2024-07-28T17:58:36Z&se=2024-08-05T01:58:36Z&spr=https&sv=2022-11-02&sr=b&sig=P3mH1m6xY95UPp5qT24l6j2l9V82p8vGEx2tTQP4fF0%3D",
|
| 981 |
+
'["What is the grace period for premium payment?","What is the waiting period for Pre-existing Diseases?","is maternity covered in this policy?"]'
|
| 982 |
+
]
|
| 983 |
+
],
|
| 984 |
+
inputs=[hack_url, hack_questions],
|
| 985 |
+
label="Sample Insurance Policy Analysis"
|
| 986 |
+
)
|
| 987 |
+
|
| 988 |
+
with gr.Row():
|
| 989 |
+
hack_clear_btn = gr.Button("🗑️ Clear", variant="secondary", size="sm")
|
| 990 |
+
hack_submit_btn = gr.Button("🚀 Process Submission", variant="primary", size="lg")
|
| 991 |
+
|
| 992 |
+
hack_status = gr.Markdown(visible=False, elem_classes="status-text")
|
| 993 |
+
|
| 994 |
+
# --- Single Query Analysis Tab ---
|
| 995 |
+
with gr.Tab("🔍 Single Query Analysis", id=1):
|
| 996 |
+
with gr.Column(elem_classes="tab-content"):
|
| 997 |
+
gr.HTML('<h3 class="section-title">🔍 Detailed Document Query</h3>')
|
| 998 |
+
|
| 999 |
+
single_url = gr.Textbox(
|
| 1000 |
+
label="📄 Document URL",
|
| 1001 |
+
placeholder="Enter the public URL of the document...",
|
| 1002 |
+
lines=2,
|
| 1003 |
+
info="URL to your PDF or DOCX document"
|
| 1004 |
+
)
|
| 1005 |
+
|
| 1006 |
+
single_question = gr.Textbox(
|
| 1007 |
+
label="❓ Your Question",
|
| 1008 |
+
placeholder="What is the waiting period for cataract surgery?",
|
| 1009 |
+
lines=5,
|
| 1010 |
+
info="Ask a specific question about your document"
|
| 1011 |
+
)
|
| 1012 |
+
|
| 1013 |
+
gr.HTML("""
|
| 1014 |
+
<div class="example-box">
|
| 1015 |
+
<strong>💡 Pro Tip:</strong><br>
|
| 1016 |
+
<small>Be specific in your questions for better results. Include context like "waiting period", "coverage amount", or "eligibility criteria".</small>
|
| 1017 |
+
</div>
|
| 1018 |
+
""")
|
| 1019 |
+
|
| 1020 |
+
with gr.Row():
|
| 1021 |
+
single_clear_btn = gr.Button("🗑️ Clear", variant="secondary", size="sm")
|
| 1022 |
+
single_submit_btn = gr.Button("🔍 Get Detailed Answer", variant="primary", size="lg")
|
| 1023 |
+
|
| 1024 |
+
single_status = gr.Markdown(visible=False, elem_classes="status-text")
|
| 1025 |
+
|
| 1026 |
+
# --- Right Column: Outputs ---
|
| 1027 |
+
with gr.Column(scale=2):
|
| 1028 |
+
with gr.Column(elem_classes="output-container"):
|
| 1029 |
+
gr.HTML('<h3 class="section-title">📊 Analysis Results</h3>')
|
| 1030 |
+
|
| 1031 |
+
with gr.Tabs():
|
| 1032 |
+
with gr.Tab("✅ Hackathon Results", id=2):
|
| 1033 |
+
hack_output = gr.Textbox(
|
| 1034 |
+
label="📊 Hackathon JSON Response",
|
| 1035 |
+
lines=25,
|
| 1036 |
+
max_lines=35,
|
| 1037 |
+
interactive=False,
|
| 1038 |
+
info="Complete JSON response with all answers and metadata",
|
| 1039 |
+
show_copy_button=True
|
| 1040 |
+
)
|
| 1041 |
|
| 1042 |
+
with gr.Tab("🔍 Single Query Results", id=3):
|
| 1043 |
+
single_output = gr.Textbox(
|
| 1044 |
+
label="📋 Detailed Single Query Response",
|
| 1045 |
+
lines=25,
|
| 1046 |
+
max_lines=35,
|
| 1047 |
+
interactive=False,
|
| 1048 |
+
info="Comprehensive answer with supporting context",
|
| 1049 |
+
show_copy_button=True
|
| 1050 |
+
)
|
| 1051 |
|
| 1052 |
+
# --- Footer ---
|
| 1053 |
+
gr.HTML("""
|
| 1054 |
+
<div style="text-align: center; padding: 2rem; color: #64748b; border-top: 1px solid #e2e8f0; margin-top: 2rem;">
|
| 1055 |
+
<p><strong>⚡ Optimized for Enterprise Document Processing</strong></p>
|
| 1056 |
+
<p>Built with advanced RAG architecture for maximum accuracy and speed</p>
|
| 1057 |
+
</div>
|
| 1058 |
+
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1059 |
|
| 1060 |
# --- Event Handlers ---
|
| 1061 |
|
|
|
|
| 1063 |
hack_submit_btn.click(
|
| 1064 |
fn=hackathon_wrapper,
|
| 1065 |
inputs=[hack_url, hack_questions],
|
| 1066 |
+
outputs=[hack_status, hack_output]
|
| 1067 |
+
)
|
| 1068 |
+
|
| 1069 |
+
hack_clear_btn.click(
|
| 1070 |
+
lambda: (None, None, None, gr.Markdown(visible=False)),
|
| 1071 |
+
outputs=[hack_url, hack_questions, hack_output, hack_status]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1072 |
)
|
|
|
|
| 1073 |
|
| 1074 |
# Single Query Tab Logic
|
| 1075 |
single_submit_btn.click(
|
| 1076 |
fn=single_query_wrapper,
|
| 1077 |
inputs=[single_url, single_question],
|
| 1078 |
+
outputs=[single_status, single_output]
|
| 1079 |
+
)
|
| 1080 |
+
|
| 1081 |
+
single_clear_btn.click(
|
| 1082 |
+
lambda: (None, None, None, gr.Markdown(visible=False)),
|
| 1083 |
+
outputs=[single_url, single_question, single_output, single_status]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1084 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1085 |
|
| 1086 |
app = gr.mount_gradio_app(api_app, demo, path="/")
|
| 1087 |
|