Nischal Subedi commited on
Commit
03254f3
·
1 Parent(s): ca185b4
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -146,7 +146,7 @@ Answer:"""
146
  context_parts.append(f"**Source: State Summary (State: {state_label})**\n{state_doc_content}")
147
 
148
  if context_parts:
149
- context = "\n\n---\n\n".join(context_parts)
150
  logging.info(f"Constructed context with {len(context_parts)} parts. Length: {len(context)} chars.")
151
  try:
152
  statutes_from_context = self.extract_statutes(context)
@@ -171,7 +171,7 @@ Answer:"""
171
 
172
  if not answer_text:
173
  logging.warning("LLM returned an empty answer.")
174
- answer_text = "<div class='error-message'><span class='error-icon'>⚠️</span>The AI model returned an empty response. This might be due to the query, context limitations, or temporary issues. Please try rephrasing your question or try again later.</div>"
175
  else:
176
  logging.info("LLM generated answer successfully.")
177
 
@@ -194,7 +194,7 @@ Answer:"""
194
  error_message = "Error: The request to the AI model timed out. The service might be busy."
195
  details = "Please try again in a few moments."
196
 
197
- formatted_error = f"<div class='error-message'><span class='error-icon'>❌</span>{error_message}</div>"
198
  if details:
199
  formatted_error += f"<div class='error-details'>{details}</div>"
200
 
@@ -243,14 +243,14 @@ Answer:"""
243
  def gradio_interface(self):
244
  def query_interface_wrapper(api_key: str, query: str, state: str) -> str:
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 free from OpenAI</a>.</div>"
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():
250
- return "<div class='error-message'><span class='error-icon'>⚠️</span>Please enter your question in the text box.</div>"
251
 
252
  result = self.process_query(query=query, state=state, openai_api_key=api_key)
253
- answer = result.get("answer", "<div class='error-message'><span class='error-icon'>⚠️</span>An unexpected error occurred.</div>")
254
 
255
  if "<div class='error-message'>" in answer:
256
  return answer
@@ -285,7 +285,7 @@ Answer:"""
285
  example_queries.append(["What basic rights do tenants have?", "California"])
286
 
287
 
288
- # Custom CSS for a professional, light, dynamic dashboard
289
  custom_css = """
290
  /* Import legible fonts from Google Fonts */
291
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Poppins:wght@600;700;800&display=swap');
@@ -356,8 +356,8 @@ Answer:"""
356
  left: 0;
357
  width: 100%;
358
  height: 100%;
359
- background: radial-gradient(circle at top left, hsla(200, 70%, 45%, 0.05) 0%, transparent 40%),
360
- radial-gradient(circle at bottom right, hsla(200, 70%, 45%, 0.05) 0%, transparent 40%);
361
  z-index: 0;
362
  opacity: 0.8;
363
  pointer-events: none;
@@ -526,7 +526,7 @@ Answer:"""
526
  transform: translateY(-2px) !important;
527
  }
528
  .gr-button-primary:active {
529
- transform: translateY(1px) !important;
530
  box-shadow: none !important;
531
  }
532
  .gr-button-secondary {
@@ -546,7 +546,7 @@ Answer:"""
546
 
547
  /* Output Styling (Pure White Background) */
548
  .output-content-wrapper {
549
- background: var(--background-input) !important; /* Pure white background */
550
  border: 2px dashed var(--border-input) !important;
551
  border-radius: 8px !important;
552
  padding: 1.5rem !important;
 
146
  context_parts.append(f"**Source: State Summary (State: {state_label})**\n{state_doc_content}")
147
 
148
  if context_parts:
149
+ context = "\n\n---\n\n". தலைமையில்".join(context_parts)
150
  logging.info(f"Constructed context with {len(context_parts)} parts. Length: {len(context)} chars.")
151
  try:
152
  statutes_from_context = self.extract_statutes(context)
 
171
 
172
  if not answer_text:
173
  logging.warning("LLM returned an empty answer.")
174
+ answer_text = "<div class='error-message'>The AI model returned an empty response. This might be due to the query, context limitations, or temporary issues. Please try rephrasing your question or try again later.</div>"
175
  else:
176
  logging.info("LLM generated answer successfully.")
177
 
 
194
  error_message = "Error: The request to the AI model timed out. The service might be busy."
195
  details = "Please try again in a few moments."
196
 
197
+ formatted_error = f"<div class='error-message'>{error_message}</div>"
198
  if details:
199
  formatted_error += f"<div class='error-details'>{details}</div>"
200
 
 
243
  def gradio_interface(self):
244
  def query_interface_wrapper(api_key: str, query: str, state: str) -> str:
245
  if not api_key or not api_key.strip() or not api_key.startswith("sk-"):
246
+ return "<div class='error-message'>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>"
247
  if not state or state == "Select a state..." or "Error" in state:
248
+ return "<div class='error-message'>Please select a valid state from the dropdown.</div>"
249
  if not query or not query.strip():
250
+ return "<div class='error-message'>Please enter your question in the text box.</div>"
251
 
252
  result = self.process_query(query=query, state=state, openai_api_key=api_key)
253
+ answer = result.get("answer", "<div class='error-message'>An unexpected error occurred.</div>")
254
 
255
  if "<div class='error-message'>" in answer:
256
  return answer
 
285
  example_queries.append(["What basic rights do tenants have?", "California"])
286
 
287
 
288
+ # Custom CSS for a professional, clean, light, dynamic dashboard
289
  custom_css = """
290
  /* Import legible fonts from Google Fonts */
291
  @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Poppins:wght@600;700;800&display=swap');
 
356
  left: 0;
357
  width: 100%;
358
  height: 100%;
359
+ background: radial-gradient(circle at top left, hsla(210, 70%, 45%, 0.05) 0%, transparent 40%),
360
+ radial-gradient(circle at bottom right, hsla(210, 70%, 45%, 0.05) 0%, transparent 40%);
361
  z-index: 0;
362
  opacity: 0.8;
363
  pointer-events: none;
 
526
  transform: translateY(-2px) !important;
527
  }
528
  .gr-button-primary:active {
529
+ transform: translateY(1px) !important; /* Press effect */
530
  box-shadow: none !important;
531
  }
532
  .gr-button-secondary {
 
546
 
547
  /* Output Styling (Pure White Background) */
548
  .output-content-wrapper {
549
+ background: var(--background-input) !important; /* Pure white background for output box */
550
  border: 2px dashed var(--border-input) !important;
551
  border-radius: 8px !important;
552
  padding: 1.5rem !important;