Nischal Subedi
commited on
Commit
·
9d5f183
1
Parent(s):
3e20ea0
updated UI_v38
Browse files
app.py
CHANGED
@@ -6,7 +6,8 @@ import re
|
|
6 |
|
7 |
import gradio as gr
|
8 |
try:
|
9 |
-
|
|
|
10 |
except ImportError:
|
11 |
print("Error: Could not import VectorDatabase from vector_db.py.")
|
12 |
print("Please ensure vector_db.py exists in the same directory and is correctly defined.")
|
@@ -241,9 +242,9 @@ Answer:"""
|
|
241 |
# --- GRADIO INTERFACE (Complete Overhaul for Cohesion, Legibility, and Advanced Look) ---
|
242 |
def gradio_interface(self):
|
243 |
def query_interface_wrapper(api_key: str, query: str, state: str) -> str:
|
244 |
-
# Basic client-
|
245 |
if not api_key or not api_key.strip() or not api_key.startswith("sk-"):
|
246 |
-
return "<div class='error-message'><span class='error-icon'>⚠️</span>Please provide a valid OpenAI API key (starting with 'sk-'). <a href='https://platform.openai.com/api-keys' target='_blank'>Get one
|
247 |
if not state or state == "Select a state..." or "Error" in state:
|
248 |
return "<div class='error-message'><span class='error-icon'>⚠️</span>Please select a valid state from the dropdown.</div>"
|
249 |
if not query or not query.strip():
|
@@ -274,6 +275,8 @@ Answer:"""
|
|
274 |
["What are the rules for security deposit returns?", "California"],
|
275 |
["Can a landlord enter my apartment without notice?", "New York"],
|
276 |
["My landlord hasn't made necessary repairs. What can I do?", "Texas"],
|
|
|
|
|
277 |
]
|
278 |
example_queries = []
|
279 |
if available_states_list and "Error" not in available_states_list[0] and len(available_states_list) > 0:
|
@@ -298,8 +301,8 @@ Answer:"""
|
|
298 |
--card-section-bg-dark: #2A2A40;
|
299 |
--text-primary-dark: #EAEAF0;
|
300 |
--text-secondary-dark: #A0A0B0;
|
301 |
-
--accent-main-dark: #FFC107;
|
302 |
-
--accent-hover-dark: #E0A800;
|
303 |
--border-dark: #3F3F5A;
|
304 |
--shadow-dark: 0 1.2rem 3.5rem rgba(0,0,0,0.6);
|
305 |
--focus-ring-dark: rgba(255, 193, 7, 0.4);
|
@@ -313,8 +316,8 @@ Answer:"""
|
|
313 |
--card-section-bg-light: #F8F9FA;
|
314 |
--text-primary-light: #212529;
|
315 |
--text-secondary-light: #6C757D;
|
316 |
-
--accent-main-light: #007bff;
|
317 |
-
--accent-hover-light: #0056b3;
|
318 |
--border-light: #DDE2E8;
|
319 |
--shadow-light: 0 0.8rem 2.5rem rgba(0,0,0,0.15);
|
320 |
--focus-ring-light: rgba(0, 123, 255, 0.3);
|
@@ -640,6 +643,7 @@ Answer:"""
|
|
640 |
:focus-visible { outline-color: var(--accent-main-light) !important; box_shadow: 0 0 0 8px var(--focus-ring-light) !important; }
|
641 |
}
|
642 |
.gradio-button span:focus { outline: none !important; }
|
|
|
643 |
.gr-examples .gr-label, .gr-examples button.gr-button-filter, .gr-examples .label-wrap,
|
644 |
.gr-examples div[data-testid*="label-text"], .gr-examples span[data-testid*="label-text"],
|
645 |
.gr-examples div[class*="label"], .gr-examples .gr-example-label,
|
@@ -654,7 +658,7 @@ Answer:"""
|
|
654 |
font-size: 0 !important; line-height: 0 !important; position: absolute !important;
|
655 |
pointer-events: none !important;
|
656 |
}
|
657 |
-
/* Responsive Adjustments (meticulously refined)
|
658 |
@media (max-width: 1024px) {
|
659 |
.gradio-container > .flex.flex-col { max-width: 960px; padding: 0 1.5rem !important; }
|
660 |
.app-header-title { font-size: 3.8rem; } .app-header-tagline { font-size: 1.5rem; }
|
@@ -686,7 +690,7 @@ Answer:"""
|
|
686 |
.output-card .placeholder { padding: 2.5rem 1.5rem; font-size: 1.1rem; }
|
687 |
.examples-section { padding-top: 1.2rem; }
|
688 |
.examples-section .gr-examples-table th, .examples-section .gr-examples-table td { padding: 0.9rem 1.1rem !important; font-size: 1.0rem !important; }
|
689 |
-
.app-footer-wrapper { margin-top: 0.
|
690 |
.app-footer { padding: 0 1rem !important; }
|
691 |
}
|
692 |
@media (max-width: 480px) {
|
@@ -741,9 +745,10 @@ Answer:"""
|
|
741 |
with gr.Group(elem_classes="dashboard-card-section"):
|
742 |
gr.Markdown("<h3 class='sub-section-title'>OpenAI API Key</h3>") # Centered by CSS
|
743 |
api_key_input = gr.Textbox(
|
744 |
-
label="",
|
745 |
type="password", placeholder="Enter your API key (e.g., sk-...)",
|
746 |
-
info="Required to process your query. Securely used per request, not stored. <a href='https://platform.openai.com/api-keys' target='_blank'>Get one free from OpenAI</a>.", lines=1
|
|
|
747 |
)
|
748 |
|
749 |
# --- Section 3: Query Input and State Selection Card ---
|
@@ -753,12 +758,14 @@ Answer:"""
|
|
753 |
with gr.Column(elem_classes="input-field", scale=3):
|
754 |
query_input = gr.Textbox(
|
755 |
label="Question", placeholder="E.g., What are the rules for security deposit returns in my state?",
|
756 |
-
lines=5, max_lines=10
|
|
|
757 |
)
|
758 |
with gr.Column(elem_classes="input-field", scale=1):
|
759 |
state_input = gr.Dropdown(
|
760 |
label="Select State", choices=dropdown_choices, value=initial_value,
|
761 |
-
allow_custom_value=False
|
|
|
762 |
)
|
763 |
with gr.Row(elem_classes="button-row"):
|
764 |
clear_button = gr.Button("Clear", variant="secondary", elem_classes=["gr-button-secondary"])
|
@@ -779,7 +786,8 @@ Answer:"""
|
|
779 |
gr.Examples(
|
780 |
examples=example_queries, inputs=[query_input, state_input],
|
781 |
examples_per_page=5,
|
782 |
-
label="",
|
|
|
783 |
)
|
784 |
else:
|
785 |
gr.Markdown("<div class='placeholder'>Sample questions could not be loaded.</div>")
|
|
|
6 |
|
7 |
import gradio as gr
|
8 |
try:
|
9 |
+
# Assuming vector_db.py exists in the same directory or is installed
|
10 |
+
from vector_db import VectorDatabase
|
11 |
except ImportError:
|
12 |
print("Error: Could not import VectorDatabase from vector_db.py.")
|
13 |
print("Please ensure vector_db.py exists in the same directory and is correctly defined.")
|
|
|
242 |
# --- GRADIO INTERFACE (Complete Overhaul for Cohesion, Legibility, and Advanced Look) ---
|
243 |
def gradio_interface(self):
|
244 |
def query_interface_wrapper(api_key: str, query: str, state: str) -> str:
|
245 |
+
# Basic client-side validation for immediate feedback (redundant but good UX)
|
246 |
if not api_key or not api_key.strip() or not api_key.startswith("sk-"):
|
247 |
+
return "<div class='error-message'><span class='error-icon'>⚠️</span>Please provide a valid OpenAI API key (starting with 'sk-'). <a href='https://platform.openai.com/api-keys' target='_blank'>Get one free from OpenAI</a>.</div>"
|
248 |
if not state or state == "Select a state..." or "Error" in state:
|
249 |
return "<div class='error-message'><span class='error-icon'>⚠️</span>Please select a valid state from the dropdown.</div>"
|
250 |
if not query or not query.strip():
|
|
|
275 |
["What are the rules for security deposit returns?", "California"],
|
276 |
["Can a landlord enter my apartment without notice?", "New York"],
|
277 |
["My landlord hasn't made necessary repairs. What can I do?", "Texas"],
|
278 |
+
["How much notice must a landlord give to raise rent?", "Florida"],
|
279 |
+
["What is an implied warranty of habitability?", "Illinois"]
|
280 |
]
|
281 |
example_queries = []
|
282 |
if available_states_list and "Error" not in available_states_list[0] and len(available_states_list) > 0:
|
|
|
301 |
--card-section-bg-dark: #2A2A40;
|
302 |
--text-primary-dark: #EAEAF0;
|
303 |
--text-secondary-dark: #A0A0B0;
|
304 |
+
--accent-main-dark: #FFC107; /* Goldenrod/Amber */
|
305 |
+
--accent-hover-dark: #E0A800; /* Darker Goldenrod */
|
306 |
--border-dark: #3F3F5A;
|
307 |
--shadow-dark: 0 1.2rem 3.5rem rgba(0,0,0,0.6);
|
308 |
--focus-ring-dark: rgba(255, 193, 7, 0.4);
|
|
|
316 |
--card-section-bg-light: #F8F9FA;
|
317 |
--text-primary-light: #212529;
|
318 |
--text-secondary-light: #6C757D;
|
319 |
+
--accent-main-light: #007bff; /* Standard Blue */
|
320 |
+
--accent-hover-light: #0056b3; /* Darker Blue */
|
321 |
--border-light: #DDE2E8;
|
322 |
--shadow-light: 0 0.8rem 2.5rem rgba(0,0,0,0.15);
|
323 |
--focus-ring-light: rgba(0, 123, 255, 0.3);
|
|
|
643 |
:focus-visible { outline-color: var(--accent-main-light) !important; box_shadow: 0 0 0 8px var(--focus-ring-light) !important; }
|
644 |
}
|
645 |
.gradio-button span:focus { outline: none !important; }
|
646 |
+
/* Hide default Gradio example labels and related elements for cleaner presentation */
|
647 |
.gr-examples .gr-label, .gr-examples button.gr-button-filter, .gr-examples .label-wrap,
|
648 |
.gr-examples div[data-testid*="label-text"], .gr-examples span[data-testid*="label-text"],
|
649 |
.gr-examples div[class*="label"], .gr-examples .gr-example-label,
|
|
|
658 |
font-size: 0 !important; line-height: 0 !important; position: absolute !important;
|
659 |
pointer-events: none !important;
|
660 |
}
|
661 |
+
/* Responsive Adjustments (meticulously refined) */
|
662 |
@media (max-width: 1024px) {
|
663 |
.gradio-container > .flex.flex-col { max-width: 960px; padding: 0 1.5rem !important; }
|
664 |
.app-header-title { font-size: 3.8rem; } .app-header-tagline { font-size: 1.5rem; }
|
|
|
690 |
.output-card .placeholder { padding: 2.5rem 1.5rem; font-size: 1.1rem; }
|
691 |
.examples-section { padding-top: 1.2rem; }
|
692 |
.examples-section .gr-examples-table th, .examples-section .gr-examples-table td { padding: 0.9rem 1.1rem !important; font-size: 1.0rem !important; }
|
693 |
+
.app-footer-wrapper { margin-top: 0.6rem; border-top-left-radius: var(--radius-md); border-top-right-radius: var(--radius-md); padding-top: 2rem; padding-bottom: 2rem; }
|
694 |
.app-footer { padding: 0 1rem !important; }
|
695 |
}
|
696 |
@media (max-width: 480px) {
|
|
|
745 |
with gr.Group(elem_classes="dashboard-card-section"):
|
746 |
gr.Markdown("<h3 class='sub-section-title'>OpenAI API Key</h3>") # Centered by CSS
|
747 |
api_key_input = gr.Textbox(
|
748 |
+
label="", # Label hidden by CSS, custom label below
|
749 |
type="password", placeholder="Enter your API key (e.g., sk-...)",
|
750 |
+
info="Required to process your query. Securely used per request, not stored. <a href='https://platform.openai.com/api-keys' target='_blank'>Get one free from OpenAI</a>.", lines=1,
|
751 |
+
elem_classes=["input-field-group"]
|
752 |
)
|
753 |
|
754 |
# --- Section 3: Query Input and State Selection Card ---
|
|
|
758 |
with gr.Column(elem_classes="input-field", scale=3):
|
759 |
query_input = gr.Textbox(
|
760 |
label="Question", placeholder="E.g., What are the rules for security deposit returns in my state?",
|
761 |
+
lines=5, max_lines=10,
|
762 |
+
elem_classes=["input-field-group"]
|
763 |
)
|
764 |
with gr.Column(elem_classes="input-field", scale=1):
|
765 |
state_input = gr.Dropdown(
|
766 |
label="Select State", choices=dropdown_choices, value=initial_value,
|
767 |
+
allow_custom_value=False,
|
768 |
+
elem_classes=["input-field-group"]
|
769 |
)
|
770 |
with gr.Row(elem_classes="button-row"):
|
771 |
clear_button = gr.Button("Clear", variant="secondary", elem_classes=["gr-button-secondary"])
|
|
|
786 |
gr.Examples(
|
787 |
examples=example_queries, inputs=[query_input, state_input],
|
788 |
examples_per_page=5,
|
789 |
+
label="", # Label hidden by CSS
|
790 |
+
elem_classes=["gr-examples-table"] # Custom class for table styling
|
791 |
)
|
792 |
else:
|
793 |
gr.Markdown("<div class='placeholder'>Sample questions could not be loaded.</div>")
|