Update app.py
Browse files
app.py
CHANGED
@@ -589,26 +589,53 @@ elif option == "Symptom Checker":
|
|
589 |
|
590 |
elif option == "Doctor Connect":
|
591 |
st.subheader("π₯ Find a Doctor Near You")
|
592 |
-
lat, lon = get_user_location()
|
593 |
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
598 |
geolocator = Nominatim(user_agent="geoapi")
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
604 |
|
|
|
605 |
if lat and lon:
|
606 |
-
st.success(f"π Location detected: {lat}, {lon}")
|
607 |
map_ = folium.Map(location=[lat, lon], zoom_start=13)
|
608 |
folium.Marker([lat, lon], popup="You are here!", icon=folium.Icon(color="blue")).add_to(map_)
|
|
|
609 |
folium_static(map_)
|
610 |
|
611 |
|
|
|
612 |
# elif option == "Doctor Connect":
|
613 |
# st.subheader("π Doctor Connect - Find Nearby Hospitals")
|
614 |
|
|
|
589 |
|
590 |
elif option == "Doctor Connect":
|
591 |
st.subheader("π₯ Find a Doctor Near You")
|
|
|
592 |
|
593 |
+
def get_browser_location():
|
594 |
+
try:
|
595 |
+
# Use IP-based lookup as fallback (may be inaccurate)
|
596 |
+
response = requests.get("https://ipinfo.io/json").json()
|
597 |
+
loc = response["loc"].split(",")
|
598 |
+
return float(loc[0]), float(loc[1])
|
599 |
+
except:
|
600 |
+
return None, None
|
601 |
+
|
602 |
+
location_choice = st.radio("How would you like to set your location?", ("Use My Location", "Enter Manually"))
|
603 |
+
|
604 |
+
lat, lon = None, None
|
605 |
+
|
606 |
+
if location_choice == "Use My Location":
|
607 |
+
lat, lon = get_browser_location()
|
608 |
+
if lat and lon:
|
609 |
+
st.success(f"π Location detected: {lat:.4f}, {lon:.4f}")
|
610 |
+
else:
|
611 |
+
st.warning("β οΈ Could not detect your location. Please enter it manually.")
|
612 |
+
else:
|
613 |
+
manual_input = st.text_input("Enter your location (City, State or Latitude,Longitude):")
|
614 |
+
if manual_input:
|
615 |
geolocator = Nominatim(user_agent="geoapi")
|
616 |
+
try:
|
617 |
+
if "," in manual_input:
|
618 |
+
parts = manual_input.split(",")
|
619 |
+
lat = float(parts[0].strip())
|
620 |
+
lon = float(parts[1].strip())
|
621 |
+
else:
|
622 |
+
location = geolocator.geocode(manual_input)
|
623 |
+
if location:
|
624 |
+
lat, lon = location.latitude, location.longitude
|
625 |
+
else:
|
626 |
+
st.error("β Could not find that location.")
|
627 |
+
except:
|
628 |
+
st.error("β οΈ Invalid input. Please try again.")
|
629 |
|
630 |
+
# Show map if valid coordinates
|
631 |
if lat and lon:
|
|
|
632 |
map_ = folium.Map(location=[lat, lon], zoom_start=13)
|
633 |
folium.Marker([lat, lon], popup="You are here!", icon=folium.Icon(color="blue")).add_to(map_)
|
634 |
+
st.write("π Your Location on Map:")
|
635 |
folium_static(map_)
|
636 |
|
637 |
|
638 |
+
|
639 |
# elif option == "Doctor Connect":
|
640 |
# st.subheader("π Doctor Connect - Find Nearby Hospitals")
|
641 |
|