Nischal Subedi
commited on
Commit
·
97ad337
1
Parent(s):
2f0012b
UI v33
Browse files
app.py
CHANGED
|
@@ -247,7 +247,7 @@ Answer:"""
|
|
| 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'>
|
| 251 |
if not state or state == "Select a state..." or "Error" in state:
|
| 252 |
return "<div class='error-message'><span class='error-icon'>⚠️</span>Please select a valid state from the dropdown.</div>"
|
| 253 |
if not query or not query.strip():
|
|
@@ -334,7 +334,7 @@ Answer:"""
|
|
| 334 |
--error-text: #FF6666;
|
| 335 |
}
|
| 336 |
|
| 337 |
-
/* Ensure the very outer background is also set, overriding any Gradio defaults */
|
| 338 |
body, html {
|
| 339 |
background-color: var(--background-secondary) !important;
|
| 340 |
}
|
|
@@ -360,11 +360,18 @@ Answer:"""
|
|
| 360 |
border-radius: 16px !important;
|
| 361 |
padding: 2.5rem 1.5rem !important; /* More vertical padding */
|
| 362 |
margin-bottom: 1.5rem !important;
|
| 363 |
-
text-align: center !important; /* Center text within header */
|
| 364 |
box-shadow: var(--shadow-md) !important;
|
| 365 |
position: relative; /* For potential pseudo-element effects */
|
| 366 |
overflow: hidden; /* For any overflow animations */
|
| 367 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 368 |
.app-header-wrapper::before { /* Subtle background pattern for dynamism */
|
| 369 |
content: '';
|
| 370 |
position: absolute;
|
|
@@ -406,6 +413,7 @@ Answer:"""
|
|
| 406 |
letter-spacing: -0.03em !important; /* Tighter spacing */
|
| 407 |
position: relative;
|
| 408 |
z-index: 1;
|
|
|
|
| 409 |
}
|
| 410 |
.app-header-tagline {
|
| 411 |
font-size: 1.25rem !important; /* Slightly larger tagline */
|
|
@@ -413,10 +421,9 @@ Answer:"""
|
|
| 413 |
font-weight: 400 !important;
|
| 414 |
margin: 0 !important;
|
| 415 |
max-width: 700px; /* Constrain tagline width */
|
| 416 |
-
margin-left: auto;
|
| 417 |
-
margin-right: auto;
|
| 418 |
position: relative;
|
| 419 |
z-index: 1;
|
|
|
|
| 420 |
}
|
| 421 |
|
| 422 |
/* Main container with consistent spacing */
|
|
@@ -425,7 +432,7 @@ Answer:"""
|
|
| 425 |
flex-direction: column !important;
|
| 426 |
gap: 1.25rem !important; /* Consistent spacing between cards */
|
| 427 |
}
|
| 428 |
-
/* Card sections with clear boundaries
|
| 429 |
.dashboard-card-section {
|
| 430 |
background-color: var(--background-primary) !important; /* Explicitly set background */
|
| 431 |
border: 2px solid var(--border-color) !important; /* Distinct border */
|
|
@@ -440,17 +447,23 @@ Answer:"""
|
|
| 440 |
transform: translateY(-3px) !important; /* More pronounced lift */
|
| 441 |
}
|
| 442 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 443 |
/* Centered section titles with improved typography */
|
| 444 |
.sub-section-title {
|
| 445 |
font-family: 'Poppins', sans-serif !important;
|
| 446 |
font-size: 1.7rem !important; /* Slightly larger */
|
| 447 |
font-weight: 700 !important; /* Bolder */
|
| 448 |
color: var(--text-primary) !important;
|
| 449 |
-
text-align
|
| 450 |
margin: 0 0 1.25rem 0 !important; /* More space below title */
|
| 451 |
padding-bottom: 0.75rem !important;
|
| 452 |
border-bottom: 2px solid var(--border-color) !important; /* Underline effect */
|
| 453 |
-
display: block !important;
|
|
|
|
| 454 |
letter-spacing: -0.01em !important;
|
| 455 |
}
|
| 456 |
|
|
@@ -544,7 +557,7 @@ Answer:"""
|
|
| 544 |
}
|
| 545 |
.gr-button-primary:hover {
|
| 546 |
background-color: var(--primary-hover) !important; /* Explicitly set background */
|
| 547 |
-
|
| 548 |
transform: translateY(-2px) !important; /* Subtle lift effect on hover */
|
| 549 |
}
|
| 550 |
.gr-button-primary:active { /* Press down effect on click */
|
|
@@ -566,7 +579,7 @@ Answer:"""
|
|
| 566 |
box-shadow: none !important;
|
| 567 |
}
|
| 568 |
|
| 569 |
-
/* Output styling with clear boundaries
|
| 570 |
.output-content-wrapper {
|
| 571 |
background-color: var(--background-primary) !important; /* Explicitly set background */
|
| 572 |
border: 2px solid var(--border-color) !important; /* Clear border */
|
|
@@ -761,11 +774,11 @@ Answer:"""
|
|
| 761 |
}
|
| 762 |
"""
|
| 763 |
|
| 764 |
-
# Using gr.Blocks with custom CSS only to ensure no
|
| 765 |
with gr.Blocks(css=custom_css, title="Landlord-Tenant Rights Assistant") as demo:
|
| 766 |
# Header Section - uses gr.Group for distinct card-like styling
|
| 767 |
with gr.Group(elem_classes="app-header-wrapper"):
|
| 768 |
-
# Markdown used for flexible styling and
|
| 769 |
gr.Markdown(
|
| 770 |
"""
|
| 771 |
<div class="app-header">
|
|
@@ -781,7 +794,8 @@ Answer:"""
|
|
| 781 |
|
| 782 |
# Introduction and Disclaimer Card
|
| 783 |
with gr.Group(elem_classes="dashboard-card-section"):
|
| 784 |
-
|
|
|
|
| 785 |
gr.Markdown(
|
| 786 |
"""
|
| 787 |
Navigate landlord-tenant laws with ease. This assistant provides detailed, state-specific answers grounded in legal authority.
|
|
@@ -792,7 +806,8 @@ Answer:"""
|
|
| 792 |
|
| 793 |
# OpenAI API Key Input Card
|
| 794 |
with gr.Group(elem_classes="dashboard-card-section"):
|
| 795 |
-
|
|
|
|
| 796 |
api_key_input = gr.Textbox(
|
| 797 |
label="API Key",
|
| 798 |
type="password", # Hides the input for security
|
|
@@ -804,7 +819,8 @@ Answer:"""
|
|
| 804 |
|
| 805 |
# Query Input and State Selection Card
|
| 806 |
with gr.Group(elem_classes="dashboard-card-section"):
|
| 807 |
-
|
|
|
|
| 808 |
with gr.Row(elem_classes="input-row"): # Row for side-by-side query and state
|
| 809 |
with gr.Column(elem_classes="input-field", scale=3): # Query text area takes more space
|
| 810 |
query_input = gr.Textbox(
|
|
@@ -828,7 +844,8 @@ Answer:"""
|
|
| 828 |
|
| 829 |
# Output Display Card - Using gr.HTML for better animation control
|
| 830 |
with gr.Group(elem_classes="dashboard-card-section"):
|
| 831 |
-
|
|
|
|
| 832 |
output = gr.HTML( # Changed to gr.HTML to wrap content with animation class
|
| 833 |
value="<div class='placeholder'>The answer will appear here after submitting your query.</div>",
|
| 834 |
elem_classes="output-content-wrapper" # Custom class for output styling
|
|
@@ -836,7 +853,8 @@ Answer:"""
|
|
| 836 |
|
| 837 |
# Example Questions Section
|
| 838 |
with gr.Group(elem_classes="dashboard-card-section examples-section"):
|
| 839 |
-
|
|
|
|
| 840 |
if example_queries:
|
| 841 |
gr.Examples(
|
| 842 |
examples=example_queries,
|
|
|
|
| 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 == "Select a state..." or "Error" in state:
|
| 252 |
return "<div class='error-message'><span class='error-icon'>⚠️</span>Please select a valid state from the dropdown.</div>"
|
| 253 |
if not query or not query.strip():
|
|
|
|
| 334 |
--error-text: #FF6666;
|
| 335 |
}
|
| 336 |
|
| 337 |
+
/* Ensure the very outer body background is also set, overriding any Gradio defaults */
|
| 338 |
body, html {
|
| 339 |
background-color: var(--background-secondary) !important;
|
| 340 |
}
|
|
|
|
| 360 |
border-radius: 16px !important;
|
| 361 |
padding: 2.5rem 1.5rem !important; /* More vertical padding */
|
| 362 |
margin-bottom: 1.5rem !important;
|
|
|
|
| 363 |
box-shadow: var(--shadow-md) !important;
|
| 364 |
position: relative; /* For potential pseudo-element effects */
|
| 365 |
overflow: hidden; /* For any overflow animations */
|
| 366 |
}
|
| 367 |
+
/* The container for the logo, title, and tagline */
|
| 368 |
+
.app-header {
|
| 369 |
+
display: flex !important;
|
| 370 |
+
flex-direction: column !important;
|
| 371 |
+
align-items: center !important; /* This centers children horizontally */
|
| 372 |
+
width: 100% !important; /* Ensure it takes full width to center effectively */
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
.app-header-wrapper::before { /* Subtle background pattern for dynamism */
|
| 376 |
content: '';
|
| 377 |
position: absolute;
|
|
|
|
| 413 |
letter-spacing: -0.03em !important; /* Tighter spacing */
|
| 414 |
position: relative;
|
| 415 |
z-index: 1;
|
| 416 |
+
text-align: center; /* Redundant due to flexbox, but good for fallback */
|
| 417 |
}
|
| 418 |
.app-header-tagline {
|
| 419 |
font-size: 1.25rem !important; /* Slightly larger tagline */
|
|
|
|
| 421 |
font-weight: 400 !important;
|
| 422 |
margin: 0 !important;
|
| 423 |
max-width: 700px; /* Constrain tagline width */
|
|
|
|
|
|
|
| 424 |
position: relative;
|
| 425 |
z-index: 1;
|
| 426 |
+
text-align: center; /* Redundant due to flexbox, but good for fallback */
|
| 427 |
}
|
| 428 |
|
| 429 |
/* Main container with consistent spacing */
|
|
|
|
| 432 |
flex-direction: column !important;
|
| 433 |
gap: 1.25rem !important; /* Consistent spacing between cards */
|
| 434 |
}
|
| 435 |
+
/* Card sections with clear boundaries and subtle dynamic effects */
|
| 436 |
.dashboard-card-section {
|
| 437 |
background-color: var(--background-primary) !important; /* Explicitly set background */
|
| 438 |
border: 2px solid var(--border-color) !important; /* Distinct border */
|
|
|
|
| 447 |
transform: translateY(-3px) !important; /* More pronounced lift */
|
| 448 |
}
|
| 449 |
|
| 450 |
+
/* Class to center content within Markdown blocks for titles */
|
| 451 |
+
.centered-markdown-content {
|
| 452 |
+
text-align: center !important;
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
/* Centered section titles with improved typography */
|
| 456 |
.sub-section-title {
|
| 457 |
font-family: 'Poppins', sans-serif !important;
|
| 458 |
font-size: 1.7rem !important; /* Slightly larger */
|
| 459 |
font-weight: 700 !important; /* Bolder */
|
| 460 |
color: var(--text-primary) !important;
|
| 461 |
+
/* Removed text-align here, handled by parent .centered-markdown-content */
|
| 462 |
margin: 0 0 1.25rem 0 !important; /* More space below title */
|
| 463 |
padding-bottom: 0.75rem !important;
|
| 464 |
border-bottom: 2px solid var(--border-color) !important; /* Underline effect */
|
| 465 |
+
display: block !important; /* Ensure it's a block level element for border-bottom to span */
|
| 466 |
+
width: 100% !important; /* Ensure it takes full width of its parent */
|
| 467 |
letter-spacing: -0.01em !important;
|
| 468 |
}
|
| 469 |
|
|
|
|
| 557 |
}
|
| 558 |
.gr-button-primary:hover {
|
| 559 |
background-color: var(--primary-hover) !important; /* Explicitly set background */
|
| 560 |
+
box_shadow: var(--shadow-md) !important;
|
| 561 |
transform: translateY(-2px) !important; /* Subtle lift effect on hover */
|
| 562 |
}
|
| 563 |
.gr-button-primary:active { /* Press down effect on click */
|
|
|
|
| 579 |
box-shadow: none !important;
|
| 580 |
}
|
| 581 |
|
| 582 |
+
/* Output styling with clear boundaries and dynamic fade-in */
|
| 583 |
.output-content-wrapper {
|
| 584 |
background-color: var(--background-primary) !important; /* Explicitly set background */
|
| 585 |
border: 2px solid var(--border-color) !important; /* Clear border */
|
|
|
|
| 774 |
}
|
| 775 |
"""
|
| 776 |
|
| 777 |
+
# Using gr.Blocks with custom CSS only to ensure no undesired colors are inherited from a theme.
|
| 778 |
with gr.Blocks(css=custom_css, title="Landlord-Tenant Rights Assistant") as demo:
|
| 779 |
# Header Section - uses gr.Group for distinct card-like styling
|
| 780 |
with gr.Group(elem_classes="app-header-wrapper"):
|
| 781 |
+
# Markdown used for flexible styling and robust centering via flexbox
|
| 782 |
gr.Markdown(
|
| 783 |
"""
|
| 784 |
<div class="app-header">
|
|
|
|
| 794 |
|
| 795 |
# Introduction and Disclaimer Card
|
| 796 |
with gr.Group(elem_classes="dashboard-card-section"):
|
| 797 |
+
# Added elem_classes="centered-markdown-content" for robust centering
|
| 798 |
+
gr.Markdown("<h3 class='sub-section-title'>Welcome & Disclaimer</h3>", elem_classes="centered-markdown-content")
|
| 799 |
gr.Markdown(
|
| 800 |
"""
|
| 801 |
Navigate landlord-tenant laws with ease. This assistant provides detailed, state-specific answers grounded in legal authority.
|
|
|
|
| 806 |
|
| 807 |
# OpenAI API Key Input Card
|
| 808 |
with gr.Group(elem_classes="dashboard-card-section"):
|
| 809 |
+
# Added elem_classes="centered-markdown-content" for robust centering
|
| 810 |
+
gr.Markdown("<h3 class='sub-section-title'>OpenAI API Key</h3>", elem_classes="centered-markdown-content")
|
| 811 |
api_key_input = gr.Textbox(
|
| 812 |
label="API Key",
|
| 813 |
type="password", # Hides the input for security
|
|
|
|
| 819 |
|
| 820 |
# Query Input and State Selection Card
|
| 821 |
with gr.Group(elem_classes="dashboard-card-section"):
|
| 822 |
+
# Added elem_classes="centered-markdown-content" for robust centering
|
| 823 |
+
gr.Markdown("<h3 class='sub-section-title'>Ask Your Question</h3>", elem_classes="centered-markdown-content")
|
| 824 |
with gr.Row(elem_classes="input-row"): # Row for side-by-side query and state
|
| 825 |
with gr.Column(elem_classes="input-field", scale=3): # Query text area takes more space
|
| 826 |
query_input = gr.Textbox(
|
|
|
|
| 844 |
|
| 845 |
# Output Display Card - Using gr.HTML for better animation control
|
| 846 |
with gr.Group(elem_classes="dashboard-card-section"):
|
| 847 |
+
# Added elem_classes="centered-markdown-content" for robust centering
|
| 848 |
+
gr.Markdown("<h3 class='sub-section-title'>Legal Assistant's Response</h3>", elem_classes="centered-markdown-content")
|
| 849 |
output = gr.HTML( # Changed to gr.HTML to wrap content with animation class
|
| 850 |
value="<div class='placeholder'>The answer will appear here after submitting your query.</div>",
|
| 851 |
elem_classes="output-content-wrapper" # Custom class for output styling
|
|
|
|
| 853 |
|
| 854 |
# Example Questions Section
|
| 855 |
with gr.Group(elem_classes="dashboard-card-section examples-section"):
|
| 856 |
+
# Added elem_classes="centered-markdown-content" for robust centering
|
| 857 |
+
gr.Markdown("<h3 class='sub-section-title'>Example Questions</h3>", elem_classes="centered-markdown-content")
|
| 858 |
if example_queries:
|
| 859 |
gr.Examples(
|
| 860 |
examples=example_queries,
|