Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
# helper to get clinics by county
|
| 4 |
def get_clinics_by_county(county_name, file_path="info.txt", limit=5):
|
| 5 |
clinics = []
|
| 6 |
with open(file_path, "r", encoding="utf-8") as file:
|
| 7 |
lines = file.readlines()
|
| 8 |
-
|
| 9 |
inside_county = False
|
| 10 |
count = 0
|
| 11 |
for line in lines:
|
|
@@ -21,30 +19,24 @@ def get_clinics_by_county(county_name, file_path="info.txt", limit=5):
|
|
| 21 |
if count >= limit * 5:
|
| 22 |
break
|
| 23 |
return "\n".join(clinics) if clinics else "No clinics found for that county."
|
| 24 |
-
|
| 25 |
-
|
| 26 |
# Load clinic info (organized by county)
|
| 27 |
with open("info.txt", "r", encoding="utf-8") as file:
|
| 28 |
clinic_data = file.read().lower()
|
| 29 |
-
|
| 30 |
# Keep track of state
|
| 31 |
conversation_state = {
|
| 32 |
"stage": "intro", # intro → wait_for_choice → wait_for_eligibility / wait_for_county
|
| 33 |
"age": None,
|
| 34 |
"income": None,
|
| 35 |
}
|
| 36 |
-
|
| 37 |
program_explanations = {
|
| 38 |
"medicaid": "Medicaid (called Apple Health in Washington) is a free or low-cost health coverage program for eligible low-income adults, children, pregnant women, and people with disabilities.",
|
| 39 |
"medicare": "Medicare is a federal health insurance program mainly for people age 65 or older and certain younger people with disabilities.",
|
| 40 |
"aca": "ACA subsidies are financial help from the Affordable Care Act that reduce your monthly insurance premium based on your income.",
|
| 41 |
}
|
| 42 |
-
|
| 43 |
def find_clinic_by_county(county_name, file_path="info.txt"):
|
| 44 |
clinics = []
|
| 45 |
with open(file_path, "r", encoding="utf-8") as file:
|
| 46 |
lines = file.readlines()
|
| 47 |
-
|
| 48 |
inside = False
|
| 49 |
for line in lines:
|
| 50 |
if line.strip().lower().startswith(county_name.lower() + " county"):
|
|
@@ -55,22 +47,16 @@ def find_clinic_by_county(county_name, file_path="info.txt"):
|
|
| 55 |
break
|
| 56 |
if line.strip():
|
| 57 |
clinics.append(line.strip())
|
| 58 |
-
|
| 59 |
if not clinics:
|
| 60 |
return "Sorry, I couldn't find any clinics for that county. Please check your spelling or try a nearby county."
|
| 61 |
-
|
| 62 |
# Add Medicaid / EBT explanation
|
| 63 |
clinics.append("\n---\nMedicaid (Apple Health) is Washington’s free health insurance for low-income residents. It covers doctor visits, mental health, prescriptions, dental, and more.\n\nEBT (SNAP) helps you buy groceries if you qualify. You’ll get a card you can use at most stores.")
|
| 64 |
-
|
| 65 |
-
return "\n\n".join(clinics)
|
| 66 |
-
|
| 67 |
-
|
| 68 |
# helper to get clinics by county
|
| 69 |
def get_clinics_by_county(county_name, file_path="info.txt", limit=5):
|
| 70 |
clinics = []
|
| 71 |
with open(file_path, "r", encoding="utf-8") as file:
|
| 72 |
lines = file.readlines()
|
| 73 |
-
|
| 74 |
inside_county = False
|
| 75 |
count = 0
|
| 76 |
for line in lines:
|
|
@@ -86,22 +72,16 @@ def get_clinics_by_county(county_name, file_path="info.txt", limit=5):
|
|
| 86 |
if count >= limit * 5:
|
| 87 |
break
|
| 88 |
return "\n".join(clinics) if clinics else "No clinics found for that county."
|
| 89 |
-
|
| 90 |
-
|
| 91 |
def chatbot(message, history):
|
| 92 |
message = message.strip().lower()
|
| 93 |
-
|
| 94 |
# Check if user asks about programs
|
| 95 |
for key in program_explanations:
|
| 96 |
if key in message:
|
| 97 |
return program_explanations[key] + "\n\nAnything else you'd like help with?"
|
| 98 |
-
|
| 99 |
response = ""
|
| 100 |
-
|
| 101 |
if conversation_state["stage"] == "intro":
|
| 102 |
response = "Hi! I can help you find free clinics in your Washington county, or figure out what health programs you may qualify for."
|
| 103 |
conversation_state["stage"] = "wait_for_choice"
|
| 104 |
-
|
| 105 |
elif conversation_state["stage"] == "wait_for_choice":
|
| 106 |
if "eligib" in message or "qualify" in message or "insurance" in message:
|
| 107 |
response = "Sure, I can help with that. How old are you and what’s your yearly income?"
|
|
@@ -111,7 +91,6 @@ def chatbot(message, history):
|
|
| 111 |
conversation_state["stage"] = "wait_for_county"
|
| 112 |
else:
|
| 113 |
response = "Would you like help finding a clinic or seeing what programs you're eligible for? Just say 'clinic' or 'eligibility'."
|
| 114 |
-
|
| 115 |
elif conversation_state["stage"] == "wait_for_eligibility":
|
| 116 |
numbers = [int(w) for w in message.split() if w.isdigit()]
|
| 117 |
if len(numbers) >= 2:
|
|
@@ -130,7 +109,6 @@ def chatbot(message, history):
|
|
| 130 |
return response
|
| 131 |
else:
|
| 132 |
return "Could you tell me your age and income? For example: 'I'm 30 and make $25,000'."
|
| 133 |
-
|
| 134 |
age = conversation_state["age"]
|
| 135 |
income = conversation_state["income"]
|
| 136 |
if income < 20000:
|
|
@@ -139,29 +117,22 @@ def chatbot(message, history):
|
|
| 139 |
eligible = "ACA subsidies that reduce the cost of insurance"
|
| 140 |
else:
|
| 141 |
eligible = "some limited public programs, depending on your needs"
|
| 142 |
-
|
| 143 |
response = f"Based on what you shared, you may qualify for {eligible}. Is there anything else I can help you with?"
|
| 144 |
conversation_state["stage"] = "wait_for_choice"
|
| 145 |
-
|
| 146 |
elif conversation_state["stage"] == "wait_for_county":
|
| 147 |
county = message.strip()
|
| 148 |
clinic_info = find_clinic_by_county(county)
|
| 149 |
response = clinic_info + "\n\nNeed help with anything else?"
|
| 150 |
conversation_state["stage"] = "wait_for_choice"
|
| 151 |
-
|
| 152 |
else:
|
| 153 |
response = "I'm not sure what you meant. Would you like help with free clinics or program eligibility?"
|
| 154 |
-
|
| 155 |
return response
|
| 156 |
-
|
| 157 |
-
with gr.Blocks(css="body { background-color: #ede8e8; }") as demo:
|
| 158 |
with gr.Column():
|
| 159 |
gr.Image("heading.png", show_label=False, show_download_button=False)
|
| 160 |
gr.ChatInterface(
|
| 161 |
fn=chatbot,
|
| 162 |
title="HealthPal.io",
|
| 163 |
description="Use this chatbot to help you find affordable healthcare and figure out what medical subsidies you are eligible for!",
|
| 164 |
-
markdown=True # <-- Added this line only
|
| 165 |
)
|
| 166 |
-
|
| 167 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
# helper to get clinics by county
|
| 3 |
def get_clinics_by_county(county_name, file_path="info.txt", limit=5):
|
| 4 |
clinics = []
|
| 5 |
with open(file_path, "r", encoding="utf-8") as file:
|
| 6 |
lines = file.readlines()
|
|
|
|
| 7 |
inside_county = False
|
| 8 |
count = 0
|
| 9 |
for line in lines:
|
|
|
|
| 19 |
if count >= limit * 5:
|
| 20 |
break
|
| 21 |
return "\n".join(clinics) if clinics else "No clinics found for that county."
|
|
|
|
|
|
|
| 22 |
# Load clinic info (organized by county)
|
| 23 |
with open("info.txt", "r", encoding="utf-8") as file:
|
| 24 |
clinic_data = file.read().lower()
|
|
|
|
| 25 |
# Keep track of state
|
| 26 |
conversation_state = {
|
| 27 |
"stage": "intro", # intro → wait_for_choice → wait_for_eligibility / wait_for_county
|
| 28 |
"age": None,
|
| 29 |
"income": None,
|
| 30 |
}
|
|
|
|
| 31 |
program_explanations = {
|
| 32 |
"medicaid": "Medicaid (called Apple Health in Washington) is a free or low-cost health coverage program for eligible low-income adults, children, pregnant women, and people with disabilities.",
|
| 33 |
"medicare": "Medicare is a federal health insurance program mainly for people age 65 or older and certain younger people with disabilities.",
|
| 34 |
"aca": "ACA subsidies are financial help from the Affordable Care Act that reduce your monthly insurance premium based on your income.",
|
| 35 |
}
|
|
|
|
| 36 |
def find_clinic_by_county(county_name, file_path="info.txt"):
|
| 37 |
clinics = []
|
| 38 |
with open(file_path, "r", encoding="utf-8") as file:
|
| 39 |
lines = file.readlines()
|
|
|
|
| 40 |
inside = False
|
| 41 |
for line in lines:
|
| 42 |
if line.strip().lower().startswith(county_name.lower() + " county"):
|
|
|
|
| 47 |
break
|
| 48 |
if line.strip():
|
| 49 |
clinics.append(line.strip())
|
|
|
|
| 50 |
if not clinics:
|
| 51 |
return "Sorry, I couldn't find any clinics for that county. Please check your spelling or try a nearby county."
|
|
|
|
| 52 |
# Add Medicaid / EBT explanation
|
| 53 |
clinics.append("\n---\nMedicaid (Apple Health) is Washington’s free health insurance for low-income residents. It covers doctor visits, mental health, prescriptions, dental, and more.\n\nEBT (SNAP) helps you buy groceries if you qualify. You’ll get a card you can use at most stores.")
|
| 54 |
+
return "\n".join(clinics)
|
|
|
|
|
|
|
|
|
|
| 55 |
# helper to get clinics by county
|
| 56 |
def get_clinics_by_county(county_name, file_path="info.txt", limit=5):
|
| 57 |
clinics = []
|
| 58 |
with open(file_path, "r", encoding="utf-8") as file:
|
| 59 |
lines = file.readlines()
|
|
|
|
| 60 |
inside_county = False
|
| 61 |
count = 0
|
| 62 |
for line in lines:
|
|
|
|
| 72 |
if count >= limit * 5:
|
| 73 |
break
|
| 74 |
return "\n".join(clinics) if clinics else "No clinics found for that county."
|
|
|
|
|
|
|
| 75 |
def chatbot(message, history):
|
| 76 |
message = message.strip().lower()
|
|
|
|
| 77 |
# Check if user asks about programs
|
| 78 |
for key in program_explanations:
|
| 79 |
if key in message:
|
| 80 |
return program_explanations[key] + "\n\nAnything else you'd like help with?"
|
|
|
|
| 81 |
response = ""
|
|
|
|
| 82 |
if conversation_state["stage"] == "intro":
|
| 83 |
response = "Hi! I can help you find free clinics in your Washington county, or figure out what health programs you may qualify for."
|
| 84 |
conversation_state["stage"] = "wait_for_choice"
|
|
|
|
| 85 |
elif conversation_state["stage"] == "wait_for_choice":
|
| 86 |
if "eligib" in message or "qualify" in message or "insurance" in message:
|
| 87 |
response = "Sure, I can help with that. How old are you and what’s your yearly income?"
|
|
|
|
| 91 |
conversation_state["stage"] = "wait_for_county"
|
| 92 |
else:
|
| 93 |
response = "Would you like help finding a clinic or seeing what programs you're eligible for? Just say 'clinic' or 'eligibility'."
|
|
|
|
| 94 |
elif conversation_state["stage"] == "wait_for_eligibility":
|
| 95 |
numbers = [int(w) for w in message.split() if w.isdigit()]
|
| 96 |
if len(numbers) >= 2:
|
|
|
|
| 109 |
return response
|
| 110 |
else:
|
| 111 |
return "Could you tell me your age and income? For example: 'I'm 30 and make $25,000'."
|
|
|
|
| 112 |
age = conversation_state["age"]
|
| 113 |
income = conversation_state["income"]
|
| 114 |
if income < 20000:
|
|
|
|
| 117 |
eligible = "ACA subsidies that reduce the cost of insurance"
|
| 118 |
else:
|
| 119 |
eligible = "some limited public programs, depending on your needs"
|
|
|
|
| 120 |
response = f"Based on what you shared, you may qualify for {eligible}. Is there anything else I can help you with?"
|
| 121 |
conversation_state["stage"] = "wait_for_choice"
|
|
|
|
| 122 |
elif conversation_state["stage"] == "wait_for_county":
|
| 123 |
county = message.strip()
|
| 124 |
clinic_info = find_clinic_by_county(county)
|
| 125 |
response = clinic_info + "\n\nNeed help with anything else?"
|
| 126 |
conversation_state["stage"] = "wait_for_choice"
|
|
|
|
| 127 |
else:
|
| 128 |
response = "I'm not sure what you meant. Would you like help with free clinics or program eligibility?"
|
|
|
|
| 129 |
return response
|
| 130 |
+
with gr.Blocks(css="body { background-color: #EDE8E8; }") as demo:
|
|
|
|
| 131 |
with gr.Column():
|
| 132 |
gr.Image("heading.png", show_label=False, show_download_button=False)
|
| 133 |
gr.ChatInterface(
|
| 134 |
fn=chatbot,
|
| 135 |
title="HealthPal.io",
|
| 136 |
description="Use this chatbot to help you find affordable healthcare and figure out what medical subsidies you are eligible for!",
|
|
|
|
| 137 |
)
|
| 138 |
+
demo.launch()
|
|
|