Update thicc/app.py
Browse files- thicc/app.py +35 -1
thicc/app.py
CHANGED
|
@@ -9,11 +9,25 @@ HOSPITAL_CHOICES = list(HOSPITALS.keys())
|
|
| 9 |
PLAN_CHOICES = list(plans.SAMPLE_PLANS.keys()) + ["No Insurance"]
|
| 10 |
|
| 11 |
|
| 12 |
-
def _extract_hospital_and_plan(text
|
| 13 |
"""Best-effort extraction of hospital and plan names from free text."""
|
| 14 |
if not text:
|
| 15 |
return None, None
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
lower = text.lower()
|
| 18 |
hospital_name = None
|
| 19 |
plan_name = None
|
|
@@ -62,9 +76,29 @@ def _get_current_hospital_and_plan(message, history):
|
|
| 62 |
return hospital_name, plan_name
|
| 63 |
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
def respond(message, history):
|
| 66 |
"""Main response function - now asks for hospital/plan conversationally."""
|
| 67 |
|
|
|
|
|
|
|
|
|
|
| 68 |
# Determine the user's current hospital & plan from history/message
|
| 69 |
hospital_name, plan_name = _get_current_hospital_and_plan(message, history)
|
| 70 |
|
|
|
|
| 9 |
PLAN_CHOICES = list(plans.SAMPLE_PLANS.keys()) + ["No Insurance"]
|
| 10 |
|
| 11 |
|
| 12 |
+
def _extract_hospital_and_plan(text):
|
| 13 |
"""Best-effort extraction of hospital and plan names from free text."""
|
| 14 |
if not text:
|
| 15 |
return None, None
|
| 16 |
|
| 17 |
+
# Handle case where text might be a list (multimodal Gradio format)
|
| 18 |
+
if isinstance(text, list):
|
| 19 |
+
# Extract text content from list of content parts
|
| 20 |
+
text_parts = []
|
| 21 |
+
for part in text:
|
| 22 |
+
if isinstance(part, str):
|
| 23 |
+
text_parts.append(part)
|
| 24 |
+
elif isinstance(part, dict) and part.get("type") == "text":
|
| 25 |
+
text_parts.append(part.get("text", ""))
|
| 26 |
+
text = " ".join(text_parts)
|
| 27 |
+
|
| 28 |
+
if not text:
|
| 29 |
+
return None, None
|
| 30 |
+
|
| 31 |
lower = text.lower()
|
| 32 |
hospital_name = None
|
| 33 |
plan_name = None
|
|
|
|
| 76 |
return hospital_name, plan_name
|
| 77 |
|
| 78 |
|
| 79 |
+
def _normalize_message(text):
|
| 80 |
+
"""Convert message content to a plain string (handles Gradio's multimodal format)."""
|
| 81 |
+
if not text:
|
| 82 |
+
return ""
|
| 83 |
+
|
| 84 |
+
if isinstance(text, list):
|
| 85 |
+
text_parts = []
|
| 86 |
+
for part in text:
|
| 87 |
+
if isinstance(part, str):
|
| 88 |
+
text_parts.append(part)
|
| 89 |
+
elif isinstance(part, dict) and part.get("type") == "text":
|
| 90 |
+
text_parts.append(part.get("text", ""))
|
| 91 |
+
return " ".join(text_parts)
|
| 92 |
+
|
| 93 |
+
return text
|
| 94 |
+
|
| 95 |
+
|
| 96 |
def respond(message, history):
|
| 97 |
"""Main response function - now asks for hospital/plan conversationally."""
|
| 98 |
|
| 99 |
+
# Normalize message in case it's a list (multimodal Gradio format)
|
| 100 |
+
message = _normalize_message(message)
|
| 101 |
+
|
| 102 |
# Determine the user's current hospital & plan from history/message
|
| 103 |
hospital_name, plan_name = _get_current_hospital_and_plan(message, history)
|
| 104 |
|