Nischal Subedi commited on
Commit
cc72c3f
·
1 Parent(s): cccb1ef
Files changed (1) hide show
  1. app.py +28 -24
app.py CHANGED
@@ -249,7 +249,7 @@ Answer:"""
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 list.</div>" # Changed dropdown to list
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
 
@@ -271,7 +271,6 @@ Answer:"""
271
  # DEBUG: Print states to console to verify if data is loaded
272
  print(f"DEBUG: States loaded for selection: {available_states_list}")
273
  # Ensure "Select a state..." is always the first option
274
- # For Radio, we might want a distinct initial "no selection" state
275
  radio_choices = ["Select a state..."] + (available_states_list if available_states_list and "Error" not in available_states_list[0] else ["Error: States unavailable"])
276
  initial_value_radio = radio_choices[0] # Set initial value to the prompt
277
  except Exception as e: # Catch-all for safety
@@ -306,12 +305,12 @@ Answer:"""
306
  /* Import legible fonts from Google Fonts */
307
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Poppins:wght@600;700;800&display=swap');
308
 
309
- /* Root variables for consistent theming - adjusted for an inviting orange palette */
310
  :root {
311
  --primary-color: #FF8C00; /* Darker Orange for buttons/accents */
312
  --primary-hover: #E07B00; /* Slightly darker orange for hover */
313
- --background-primary: hsl(30, 100%, 99%); /* Very bright, almost white, but distinctly warm cream */
314
- --background-secondary: hsl(30, 100%, 96%); /* Slightly deeper, yet still very light, warm peach */
315
  --text-primary: #4A3C32; /* Dark warm brown/charcoal for main text */
316
  --text-secondary: #8C7B6F; /* Muted warm gray/brown for secondary text */
317
  --border-color: hsl(30, 70%, 85%); /* Light, warm orange-brown for borders */
@@ -353,7 +352,7 @@ Answer:"""
353
  background-color: var(--background-secondary) !important; /* Overall background of the container */
354
  box-shadow: none !important; /* Remove default gradio container shadow */
355
  }
356
- /* Ensure all main content sections use the gradient background */
357
  .main-dashboard-container > * {
358
  background: linear-gradient(145deg, var(--background-primary) 0%, var(--background-secondary) 100%) !important;
359
  }
@@ -378,8 +377,8 @@ Answer:"""
378
  left: 0;
379
  width: 100%;
380
  height: 100%;
381
- background: radial-gradient(circle at top left, rgba(255,140,0,0.2) 0%, transparent 60%), /* More vibrant orange tint */
382
- radial-gradient(circle at bottom right, rgba(255,140,0,0.2) 0%, transparent 60%);
383
  z-index: 0;
384
  opacity: 0.8;
385
  pointer-events: none;
@@ -446,7 +445,7 @@ Answer:"""
446
  transform: translateY(-3px) !important; /* More pronounced lift */
447
  }
448
 
449
- /* NEW: Class for Markdown blocks to center their content */
450
  .full-width-center {
451
  display: flex !important;
452
  justify-content: center !important;
@@ -456,7 +455,7 @@ Answer:"""
456
  }
457
 
458
  /* Section titles (h3 inside markdown) */
459
- .section-title { /* Renamed from sub-section-title for clarity */
460
  font-family: 'Poppins', sans-serif !important;
461
  font-size: 1.7rem !important; /* Slightly larger */
462
  font-weight: 700 !important; /* Bolder */
@@ -464,10 +463,10 @@ Answer:"""
464
  margin: 0 0 1.25rem 0 !important; /* More space below title */
465
  padding-bottom: 0.75rem !important;
466
  border-bottom: 2px solid var(--border-color) !important; /* Underline effect */
467
- display: block !important; /* Ensure it's a block-level element for proper width/border */
468
- text-align: center !important; /* Ensure the text within the h3 is centered */
469
- width: fit-content !important; /* Make it shrink-wrap its content */
470
- margin-left: auto !important; /* Auto margins to center block-level element */
471
  margin-right: auto !important;
472
  letter-spacing: -0.01em !important;
473
  }
@@ -510,7 +509,7 @@ Answer:"""
510
  /* Styling for the radio button group (state selection) */
511
  .gradio-radio {
512
  padding: 0 !important; /* Remove any default padding */
513
- margin-top: 0.5rem !important; /* Add a little space above */
514
  }
515
  /* Hide default radio circle/dot */
516
  .gradio-radio input[type="radio"] {
@@ -585,14 +584,16 @@ Answer:"""
585
  margin-top: 0.4rem !important; /* More space for info text */
586
  text-align: left !important; /* Ensure info text is left aligned */
587
  }
588
- /* Input row layout improvements */
589
- .input-row {
590
  display: flex !important;
591
- gap: 1.25rem !important; /* Consistent gap between query and state */
 
592
  margin-bottom: 0.5rem !important;
593
  }
594
  .input-field {
595
- flex: 1 !important;
 
596
  }
597
 
598
  /* Button styling improvements with active state for dynamism */
@@ -814,8 +815,8 @@ Answer:"""
814
  .section-title {
815
  font-size: 1.4rem !important;
816
  }
817
- .input-row {
818
- flex-direction: column !important; /* Stack inputs vertically */
819
  }
820
  .button-row {
821
  flex-direction: column !important; /* Stack buttons vertically */
@@ -883,8 +884,10 @@ Answer:"""
883
  with gr.Group(elem_classes="dashboard-card-section"):
884
  # Apply 'full-width-center' for section titles
885
  gr.Markdown("<h3 class='section-title'>Ask Your Question</h3>", elem_classes="full-width-center")
886
- with gr.Row(elem_classes="input-row"): # Row for side-by-side query and state
887
- with gr.Column(elem_classes="input-field", scale=3): # Query text area takes more space
 
 
888
  query_input = gr.Textbox(
889
  label="Your Question",
890
  placeholder="E.g., What are the rules for security deposit returns in my state?",
@@ -892,13 +895,14 @@ Answer:"""
892
  max_lines=15, # Increased max height
893
  elem_classes=["input-field-group"]
894
  )
895
- with gr.Column(elem_classes="input-field", scale=1): # State radio buttons take less space
896
  state_input = gr.Radio(
897
  label="Select State",
898
  choices=radio_choices,
899
  value=initial_value_radio,
900
  elem_classes=["input-field-group", "gradio-radio-custom"] # Added custom class for specific styling
901
  )
 
902
  with gr.Row(elem_classes="button-row"): # Row for action buttons
903
  clear_button = gr.Button("Clear", variant="secondary", elem_classes=["gr-button-secondary"])
904
  submit_button = gr.Button("Submit Query", variant="primary", elem_classes=["gr-button-primary"])
 
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 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
 
 
271
  # DEBUG: Print states to console to verify if data is loaded
272
  print(f"DEBUG: States loaded for selection: {available_states_list}")
273
  # Ensure "Select a state..." is always the first option
 
274
  radio_choices = ["Select a state..."] + (available_states_list if available_states_list and "Error" not in available_states_list[0] else ["Error: States unavailable"])
275
  initial_value_radio = radio_choices[0] # Set initial value to the prompt
276
  except Exception as e: # Catch-all for safety
 
305
  /* Import legible fonts from Google Fonts */
306
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Poppins:wght@600;700;800&display=swap');
307
 
308
+ /* Root variables for consistent theming - adjusted for a very warm, clean palette */
309
  :root {
310
  --primary-color: #FF8C00; /* Darker Orange for buttons/accents */
311
  --primary-hover: #E07B00; /* Slightly darker orange for hover */
312
+ --background-primary: hsl(30, 100%, 99%); /* Very bright, almost white, distinctly warm cream */
313
+ --background-secondary: hsl(30, 100%, 96%); /* Slightly deeper, clear, warm peach/cream */
314
  --text-primary: #4A3C32; /* Dark warm brown/charcoal for main text */
315
  --text-secondary: #8C7B6F; /* Muted warm gray/brown for secondary text */
316
  --border-color: hsl(30, 70%, 85%); /* Light, warm orange-brown for borders */
 
352
  background-color: var(--background-secondary) !important; /* Overall background of the container */
353
  box-shadow: none !important; /* Remove default gradio container shadow */
354
  }
355
+ /* Ensure all main content sections have the gradient background */
356
  .main-dashboard-container > * {
357
  background: linear-gradient(145deg, var(--background-primary) 0%, var(--background-secondary) 100%) !important;
358
  }
 
377
  left: 0;
378
  width: 100%;
379
  height: 100%;
380
+ background: radial-gradient(circle at top left, rgba(255,140,0,0.25) 0%, transparent 60%), /* More vibrant orange tint */
381
+ radial-gradient(circle at bottom right, rgba(255,140,0,0.25) 0%, transparent 60%);
382
  z-index: 0;
383
  opacity: 0.8;
384
  pointer-events: none;
 
445
  transform: translateY(-3px) !important; /* More pronounced lift */
446
  }
447
 
448
+ /* Class for Markdown blocks to center their content */
449
  .full-width-center {
450
  display: flex !important;
451
  justify-content: center !important;
 
455
  }
456
 
457
  /* Section titles (h3 inside markdown) */
458
+ .section-title {
459
  font-family: 'Poppins', sans-serif !important;
460
  font-size: 1.7rem !important; /* Slightly larger */
461
  font-weight: 700 !important; /* Bolder */
 
463
  margin: 0 0 1.25rem 0 !important; /* More space below title */
464
  padding-bottom: 0.75rem !important;
465
  border-bottom: 2px solid var(--border-color) !important; /* Underline effect */
466
+ display: block !important;
467
+ text-align: center !important;
468
+ width: fit-content !important;
469
+ margin-left: auto !important;
470
  margin-right: auto !important;
471
  letter-spacing: -0.01em !important;
472
  }
 
509
  /* Styling for the radio button group (state selection) */
510
  .gradio-radio {
511
  padding: 0 !important; /* Remove any default padding */
512
+ margin-top: 1rem !important; /* More space above radio buttons when below query */
513
  }
514
  /* Hide default radio circle/dot */
515
  .gradio-radio input[type="radio"] {
 
584
  margin-top: 0.4rem !important; /* More space for info text */
585
  text-align: left !important; /* Ensure info text is left aligned */
586
  }
587
+ /* Input column layout improvements */
588
+ .input-column { /* Renamed from .input-row */
589
  display: flex !important;
590
+ flex-direction: column !important; /* Stack items vertically */
591
+ gap: 1.25rem !important; /* Consistent gap between query and state input */
592
  margin-bottom: 0.5rem !important;
593
  }
594
  .input-field {
595
+ flex: none !important; /* Remove flex sizing as items are stacked */
596
+ width: 100% !important; /* Ensure each field takes full width */
597
  }
598
 
599
  /* Button styling improvements with active state for dynamism */
 
815
  .section-title {
816
  font-size: 1.4rem !important;
817
  }
818
+ .input-column { /* Apply vertical stacking for columns */
819
+ flex-direction: column !important;
820
  }
821
  .button-row {
822
  flex-direction: column !important; /* Stack buttons vertically */
 
884
  with gr.Group(elem_classes="dashboard-card-section"):
885
  # Apply 'full-width-center' for section titles
886
  gr.Markdown("<h3 class='section-title'>Ask Your Question</h3>", elem_classes="full-width-center")
887
+
888
+ # Changed from gr.Row to gr.Column for vertical stacking
889
+ with gr.Column(elem_classes="input-column"): # New column to stack inputs
890
+ with gr.Column(elem_classes="input-field", scale=None): # Query box takes full width
891
  query_input = gr.Textbox(
892
  label="Your Question",
893
  placeholder="E.g., What are the rules for security deposit returns in my state?",
 
895
  max_lines=15, # Increased max height
896
  elem_classes=["input-field-group"]
897
  )
898
+ with gr.Column(elem_classes="input-field", scale=None): # State radio buttons take full width below
899
  state_input = gr.Radio(
900
  label="Select State",
901
  choices=radio_choices,
902
  value=initial_value_radio,
903
  elem_classes=["input-field-group", "gradio-radio-custom"] # Added custom class for specific styling
904
  )
905
+
906
  with gr.Row(elem_classes="button-row"): # Row for action buttons
907
  clear_button = gr.Button("Clear", variant="secondary", elem_classes=["gr-button-secondary"])
908
  submit_button = gr.Button("Submit Query", variant="primary", elem_classes=["gr-button-primary"])