Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,73 +1,79 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
# =========================
|
| 4 |
-
# DATABASE YA HOSPITALS MU RWANDA (
|
| 5 |
# =========================
|
| 6 |
hospitals_data = [
|
| 7 |
{"name": "King Faisal Hospital", "province": "Kigali City", "district": "Gasabo", "sector": "Kacyiru",
|
| 8 |
-
"contact": "+250788123200", "email": "info@kingfaisalhosp.rw", "gps":
|
| 9 |
{"name": "CHUK", "province": "Kigali City", "district": "Nyarugenge", "sector": "Nyarugenge",
|
| 10 |
-
"contact": "", "email": "", "gps":
|
| 11 |
{"name": "Gahini District Hospital", "province": "Eastern Province", "district": "Kayonza", "sector": "Gahini",
|
| 12 |
-
"contact": "0781403761", "email": "gahini.hospital@moh.gov.rw", "gps":
|
| 13 |
{"name": "Rwinkwavu District Hospital", "province": "Eastern Province", "district": "Kayonza", "sector": "Rwinkwavu",
|
| 14 |
-
"contact": "0788358810", "email": "rwinkwavu.hospital@moh.gov.rw", "gps":
|
| 15 |
{"name": "CHUB (Butare University Teaching Hospital)", "province": "Southern Province", "district": "Huye", "sector": "Ngoma",
|
| 16 |
-
"contact": "", "email": "", "gps":
|
| 17 |
{"name": "Shyira Hospital", "province": "Western Province", "district": "Nyamasheke", "sector": "Bushenge",
|
| 18 |
-
"contact": "", "email": "", "gps":
|
| 19 |
{"name": "Butaro Hospital", "province": "Northern Province", "district": "Burera", "sector": "Butaro",
|
| 20 |
-
"contact": "", "email": "", "gps":
|
| 21 |
-
# Ongeraho hospitals zose wifuza, GPS na specialty
|
| 22 |
]
|
| 23 |
|
| 24 |
# =========================
|
| 25 |
-
# FUNCTION YO
|
| 26 |
# =========================
|
| 27 |
-
def
|
| 28 |
-
|
| 29 |
-
Ushobora kwandika symptom, province, district cyangwa specialty.
|
| 30 |
-
AI izasubiza ibitaro bihuye n'aho uri cyangwa specialty wifuza.
|
| 31 |
-
"""
|
| 32 |
results = hospitals_data
|
| 33 |
-
|
| 34 |
-
# Filter ku province niba yatanzwe
|
| 35 |
if province:
|
| 36 |
results = [h for h in results if h["province"].lower() == province.lower()]
|
| 37 |
-
# Filter ku district niba yatanzwe
|
| 38 |
if district:
|
| 39 |
results = [h for h in results if h["district"].lower() == district.lower()]
|
| 40 |
-
# Filter ku specialty niba yatanzwe
|
| 41 |
if specialty:
|
| 42 |
results = [h for h in results if specialty.lower() in [s.lower() for s in h["specialty"]]]
|
| 43 |
-
# Filter ku query keyword (hospital name / symptom keyword)
|
| 44 |
-
if query:
|
| 45 |
-
results = [h for h in results if query.lower() in h["name"].lower() or query.lower() in h["district"].lower() or query.lower() in h["sector"].lower()]
|
| 46 |
|
| 47 |
if not results:
|
| 48 |
-
return "Ntibitaro bibonetse. Ongera ugerageze keyword
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
-
# Format response
|
| 51 |
-
response = "🏥 Ibitaro biboneka:\n\n"
|
| 52 |
for h in results:
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
# =========================
|
| 58 |
# GRADIO INTERFACE
|
| 59 |
# =========================
|
| 60 |
iface = gr.Interface(
|
| 61 |
-
fn=
|
| 62 |
inputs=[
|
| 63 |
-
gr.Textbox(label="Andika symptom, hospital name, district cyangwa province", placeholder="Urugero: Kigali, Gahini, CHUK..."),
|
| 64 |
gr.Dropdown(label="Province (optional)", choices=[""] + [h["province"] for h in hospitals_data], type="value"),
|
| 65 |
gr.Textbox(label="District (optional)", placeholder="Akarere niba ushaka"),
|
| 66 |
gr.Dropdown(label="Specialty (optional)", choices=[""] + ["General","Maternity","Pediatrics","Surgery","Orthopedic","Psychiatric","Oncology"], type="value")
|
| 67 |
],
|
| 68 |
-
outputs="
|
| 69 |
-
title="Rwanda Healthcare AI –
|
| 70 |
-
description="Shaka ibitaro mu Rwanda
|
| 71 |
)
|
| 72 |
|
| 73 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import folium
|
| 3 |
+
from folium.plugins import MarkerCluster
|
| 4 |
+
import tempfile
|
| 5 |
+
import webbrowser
|
| 6 |
|
| 7 |
# =========================
|
| 8 |
+
# DATABASE YA HOSPITALS MU RWANDA (GPS + specialty)
|
| 9 |
# =========================
|
| 10 |
hospitals_data = [
|
| 11 |
{"name": "King Faisal Hospital", "province": "Kigali City", "district": "Gasabo", "sector": "Kacyiru",
|
| 12 |
+
"contact": "+250788123200", "email": "info@kingfaisalhosp.rw", "gps": [-1.949,30.089], "specialty": ["General","Maternity","Surgery"]},
|
| 13 |
{"name": "CHUK", "province": "Kigali City", "district": "Nyarugenge", "sector": "Nyarugenge",
|
| 14 |
+
"contact": "", "email": "", "gps": [-1.950,30.058], "specialty": ["General","Pediatrics","Emergency"]},
|
| 15 |
{"name": "Gahini District Hospital", "province": "Eastern Province", "district": "Kayonza", "sector": "Gahini",
|
| 16 |
+
"contact": "0781403761", "email": "gahini.hospital@moh.gov.rw", "gps": [-2.019,30.576], "specialty": ["General","Orthopedic"]},
|
| 17 |
{"name": "Rwinkwavu District Hospital", "province": "Eastern Province", "district": "Kayonza", "sector": "Rwinkwavu",
|
| 18 |
+
"contact": "0788358810", "email": "rwinkwavu.hospital@moh.gov.rw", "gps": [-2.151,30.565], "specialty": ["General","Maternity"]},
|
| 19 |
{"name": "CHUB (Butare University Teaching Hospital)", "province": "Southern Province", "district": "Huye", "sector": "Ngoma",
|
| 20 |
+
"contact": "", "email": "", "gps": [-2.590,29.739], "specialty": ["General","Pediatrics","Surgery"]},
|
| 21 |
{"name": "Shyira Hospital", "province": "Western Province", "district": "Nyamasheke", "sector": "Bushenge",
|
| 22 |
+
"contact": "", "email": "", "gps": [-2.482,29.155], "specialty": ["General","Maternity"]},
|
| 23 |
{"name": "Butaro Hospital", "province": "Northern Province", "district": "Burera", "sector": "Butaro",
|
| 24 |
+
"contact": "", "email": "", "gps": [-1.641,29.893], "specialty": ["General","Oncology","Pediatrics"]}
|
|
|
|
| 25 |
]
|
| 26 |
|
| 27 |
# =========================
|
| 28 |
+
# FUNCTION YO GUSHIRAHO MAP
|
| 29 |
# =========================
|
| 30 |
+
def healthcare_map(province="", district="", specialty=""):
|
| 31 |
+
# Filter hospitals
|
|
|
|
|
|
|
|
|
|
| 32 |
results = hospitals_data
|
|
|
|
|
|
|
| 33 |
if province:
|
| 34 |
results = [h for h in results if h["province"].lower() == province.lower()]
|
|
|
|
| 35 |
if district:
|
| 36 |
results = [h for h in results if h["district"].lower() == district.lower()]
|
|
|
|
| 37 |
if specialty:
|
| 38 |
results = [h for h in results if specialty.lower() in [s.lower() for s in h["specialty"]]]
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
if not results:
|
| 41 |
+
return "Ntibitaro bibonetse. Ongera ugerageze keyword cyangwa filter."
|
| 42 |
+
|
| 43 |
+
# Create folium map centered in Rwanda
|
| 44 |
+
rwanda_map = folium.Map(location=[-1.940, 29.873], zoom_start=7)
|
| 45 |
+
marker_cluster = MarkerCluster().add_to(rwanda_map)
|
| 46 |
|
|
|
|
|
|
|
| 47 |
for h in results:
|
| 48 |
+
popup_text = f"""
|
| 49 |
+
<b>{h['name']}</b><br>
|
| 50 |
+
Intara: {h['province']}<br>
|
| 51 |
+
Akarere: {h['district']}<br>
|
| 52 |
+
Umurenge: {h['sector']}<br>
|
| 53 |
+
Contact: {h['contact'] if h['contact'] else 'N/A'}<br>
|
| 54 |
+
Email: {h['email'] if h['email'] else 'N/A'}<br>
|
| 55 |
+
Specialty: {', '.join(h['specialty'])}
|
| 56 |
+
"""
|
| 57 |
+
folium.Marker(location=h["gps"], popup=popup_text).add_to(marker_cluster)
|
| 58 |
|
| 59 |
+
# Save map to temporary HTML file
|
| 60 |
+
tmp_file = tempfile.NamedTemporaryFile(suffix=".html", delete=False)
|
| 61 |
+
rwanda_map.save(tmp_file.name)
|
| 62 |
+
return tmp_file.name
|
| 63 |
|
| 64 |
# =========================
|
| 65 |
# GRADIO INTERFACE
|
| 66 |
# =========================
|
| 67 |
iface = gr.Interface(
|
| 68 |
+
fn=healthcare_map,
|
| 69 |
inputs=[
|
|
|
|
| 70 |
gr.Dropdown(label="Province (optional)", choices=[""] + [h["province"] for h in hospitals_data], type="value"),
|
| 71 |
gr.Textbox(label="District (optional)", placeholder="Akarere niba ushaka"),
|
| 72 |
gr.Dropdown(label="Specialty (optional)", choices=[""] + ["General","Maternity","Pediatrics","Surgery","Orthopedic","Psychiatric","Oncology"], type="value")
|
| 73 |
],
|
| 74 |
+
outputs=gr.File(label="Interactive Map of Hospitals"),
|
| 75 |
+
title="Rwanda Healthcare AI – Interactive Map",
|
| 76 |
+
description="Shaka ibitaro mu Rwanda, urabona hospitals kuri interactive map. Ushobora filter province, district, specialty."
|
| 77 |
)
|
| 78 |
|
| 79 |
iface.launch()
|