Nischal Subedi
commited on
Commit
·
91f08a3
1
Parent(s):
8336e55
UI update
Browse files
app.py
CHANGED
@@ -245,19 +245,14 @@ Answer:"""
|
|
245 |
# --- GRADIO INTERFACE (NEW UI DESIGN) ---
|
246 |
def gradio_interface(self):
|
247 |
def query_interface_wrapper(api_key: str, query: str, state: str) -> str:
|
248 |
-
# Basic client-side validation for immediate feedback (redundant but good UX)
|
249 |
if not api_key or not api_key.strip() or not api_key.startswith("sk-"):
|
250 |
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'>OpenAI</a>.</div>"
|
251 |
if not state or state is None:
|
252 |
return "<div class='error-message'><span class='error-icon'></span>Please select a valid state from the list.</div>"
|
253 |
if not query or not query.strip():
|
254 |
return "<div class='error-message'><span class='error-icon'></span>Please enter your question in the text box.</div>"
|
255 |
-
|
256 |
-
# Call the core processing logic
|
257 |
result = self.process_query(query=query, state=state, openai_api_key=api_key)
|
258 |
answer = result.get("answer", "<div class='error-message'><span class='error-icon'>⚠️</span>An unexpected error occurred.</div>")
|
259 |
-
|
260 |
-
# Check if the answer already contains an error message
|
261 |
if "<div class='error-message'>" in answer:
|
262 |
return answer
|
263 |
else:
|
@@ -290,10 +285,8 @@ Answer:"""
|
|
290 |
example_queries.append(["What basic rights do tenants have?", "California"])
|
291 |
|
292 |
custom_css = """
|
293 |
-
/* Import legible fonts from Google Fonts */
|
294 |
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Poppins:wght@600;700;800&display=swap');
|
295 |
-
|
296 |
-
/* Root variables for consistent theming (light mode) */
|
297 |
:root {
|
298 |
--primary-color: #FF8C00;
|
299 |
--primary-hover: #E07B00;
|
@@ -310,8 +303,7 @@ Answer:"""
|
|
310 |
--error-border: #FFD2B2;
|
311 |
--error-text: #E05C00;
|
312 |
}
|
313 |
-
|
314 |
-
/* Dark mode variables */
|
315 |
@media (prefers-color-scheme: dark) {
|
316 |
body {
|
317 |
--primary-color: #FFA500;
|
@@ -330,7 +322,7 @@ Answer:"""
|
|
330 |
--error-text: #FF6666;
|
331 |
}
|
332 |
}
|
333 |
-
|
334 |
body, html {
|
335 |
background-color: var(--background-secondary) !important;
|
336 |
color: var(--text-primary) !important;
|
@@ -913,7 +905,6 @@ Answer:"""
|
|
913 |
)
|
914 |
|
915 |
with gr.Column(elem_classes="main-dashboard-container"):
|
916 |
-
# How This Assistant Works Box
|
917 |
with gr.Group(elem_classes="dashboard-card-section"):
|
918 |
gr.Markdown("<h3 class='section-title'>How This Assistant Works</h3>", elem_classes="full-width-center section-title-gradient-bar")
|
919 |
with gr.Column(elem_classes="dashboard-card-content-area"):
|
@@ -923,7 +914,6 @@ Answer:"""
|
|
923 |
"""
|
924 |
)
|
925 |
|
926 |
-
# OpenAI API Key Input Card
|
927 |
with gr.Group(elem_classes="dashboard-card-section"):
|
928 |
gr.Markdown("<h3 class='section-title'>OpenAI API Key</h3>", elem_classes="full-width-center section-title-gradient-bar")
|
929 |
with gr.Column(elem_classes="dashboard-card-content-area"):
|
@@ -939,7 +929,6 @@ Answer:"""
|
|
939 |
elem_classes="gr-prose"
|
940 |
)
|
941 |
|
942 |
-
# Query Input and State Selection Card
|
943 |
with gr.Group(elem_classes="dashboard-card-section"):
|
944 |
gr.Markdown("<h3 class='section-title'>Ask Your Question</h3>", elem_classes="full-width-center section-title-gradient-bar")
|
945 |
with gr.Column(elem_classes="dashboard-card-content-area"):
|
@@ -964,7 +953,6 @@ Answer:"""
|
|
964 |
clear_button = gr.Button("Clear", variant="secondary", elem_classes=["gr-button-secondary"])
|
965 |
submit_button = gr.Button("Submit Query", variant="primary", elem_classes=["gr-button-primary"])
|
966 |
|
967 |
-
# Output Display Card
|
968 |
with gr.Group(elem_classes="dashboard-card-section"):
|
969 |
gr.Markdown("<h3 class='section-title'>Legal Assistant's Response</h3>", elem_classes="full-width-center section-title-gradient-bar")
|
970 |
with gr.Column(elem_classes="dashboard-card-content-area"):
|
@@ -973,7 +961,6 @@ Answer:"""
|
|
973 |
elem_classes="output-content-wrapper"
|
974 |
)
|
975 |
|
976 |
-
# Example Questions Section
|
977 |
with gr.Group(elem_classes="dashboard-card-section examples-section"):
|
978 |
gr.Markdown("<h3 class='section-title'>Example Questions</h3>", elem_classes="full-width-center section-title-gradient-bar")
|
979 |
with gr.Column(elem_classes="dashboard-card-content-area"):
|
@@ -987,7 +974,6 @@ Answer:"""
|
|
987 |
else:
|
988 |
gr.Markdown("<div class='placeholder'>Sample questions could not be loaded. Please ensure the vector database is populated.</div>")
|
989 |
|
990 |
-
# Footer Section
|
991 |
with gr.Group(elem_classes="app-footer-wrapper"):
|
992 |
gr.Markdown(
|
993 |
f"""
|
|
|
245 |
# --- GRADIO INTERFACE (NEW UI DESIGN) ---
|
246 |
def gradio_interface(self):
|
247 |
def query_interface_wrapper(api_key: str, query: str, state: str) -> str:
|
|
|
248 |
if not api_key or not api_key.strip() or not api_key.startswith("sk-"):
|
249 |
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'>OpenAI</a>.</div>"
|
250 |
if not state or state is None:
|
251 |
return "<div class='error-message'><span class='error-icon'></span>Please select a valid state from the list.</div>"
|
252 |
if not query or not query.strip():
|
253 |
return "<div class='error-message'><span class='error-icon'></span>Please enter your question in the text box.</div>"
|
|
|
|
|
254 |
result = self.process_query(query=query, state=state, openai_api_key=api_key)
|
255 |
answer = result.get("answer", "<div class='error-message'><span class='error-icon'>⚠️</span>An unexpected error occurred.</div>")
|
|
|
|
|
256 |
if "<div class='error-message'>" in answer:
|
257 |
return answer
|
258 |
else:
|
|
|
285 |
example_queries.append(["What basic rights do tenants have?", "California"])
|
286 |
|
287 |
custom_css = """
|
|
|
288 |
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Poppins:wght@600;700;800&display=swap');
|
289 |
+
|
|
|
290 |
:root {
|
291 |
--primary-color: #FF8C00;
|
292 |
--primary-hover: #E07B00;
|
|
|
303 |
--error-border: #FFD2B2;
|
304 |
--error-text: #E05C00;
|
305 |
}
|
306 |
+
|
|
|
307 |
@media (prefers-color-scheme: dark) {
|
308 |
body {
|
309 |
--primary-color: #FFA500;
|
|
|
322 |
--error-text: #FF6666;
|
323 |
}
|
324 |
}
|
325 |
+
|
326 |
body, html {
|
327 |
background-color: var(--background-secondary) !important;
|
328 |
color: var(--text-primary) !important;
|
|
|
905 |
)
|
906 |
|
907 |
with gr.Column(elem_classes="main-dashboard-container"):
|
|
|
908 |
with gr.Group(elem_classes="dashboard-card-section"):
|
909 |
gr.Markdown("<h3 class='section-title'>How This Assistant Works</h3>", elem_classes="full-width-center section-title-gradient-bar")
|
910 |
with gr.Column(elem_classes="dashboard-card-content-area"):
|
|
|
914 |
"""
|
915 |
)
|
916 |
|
|
|
917 |
with gr.Group(elem_classes="dashboard-card-section"):
|
918 |
gr.Markdown("<h3 class='section-title'>OpenAI API Key</h3>", elem_classes="full-width-center section-title-gradient-bar")
|
919 |
with gr.Column(elem_classes="dashboard-card-content-area"):
|
|
|
929 |
elem_classes="gr-prose"
|
930 |
)
|
931 |
|
|
|
932 |
with gr.Group(elem_classes="dashboard-card-section"):
|
933 |
gr.Markdown("<h3 class='section-title'>Ask Your Question</h3>", elem_classes="full-width-center section-title-gradient-bar")
|
934 |
with gr.Column(elem_classes="dashboard-card-content-area"):
|
|
|
953 |
clear_button = gr.Button("Clear", variant="secondary", elem_classes=["gr-button-secondary"])
|
954 |
submit_button = gr.Button("Submit Query", variant="primary", elem_classes=["gr-button-primary"])
|
955 |
|
|
|
956 |
with gr.Group(elem_classes="dashboard-card-section"):
|
957 |
gr.Markdown("<h3 class='section-title'>Legal Assistant's Response</h3>", elem_classes="full-width-center section-title-gradient-bar")
|
958 |
with gr.Column(elem_classes="dashboard-card-content-area"):
|
|
|
961 |
elem_classes="output-content-wrapper"
|
962 |
)
|
963 |
|
|
|
964 |
with gr.Group(elem_classes="dashboard-card-section examples-section"):
|
965 |
gr.Markdown("<h3 class='section-title'>Example Questions</h3>", elem_classes="full-width-center section-title-gradient-bar")
|
966 |
with gr.Column(elem_classes="dashboard-card-content-area"):
|
|
|
974 |
else:
|
975 |
gr.Markdown("<div class='placeholder'>Sample questions could not be loaded. Please ensure the vector database is populated.</div>")
|
976 |
|
|
|
977 |
with gr.Group(elem_classes="app-footer-wrapper"):
|
978 |
gr.Markdown(
|
979 |
f"""
|