MayankGupta06 commited on
Commit
6156310
Β·
verified Β·
1 Parent(s): b78a176

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -11
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
- if lat is None or lon is None:
595
- st.warning("Unable to fetch location. Please allow location access or enter manually.")
596
- address = st.text_input("Enter your location (City, State or Latitude, Longitude):")
597
- if address:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
598
  geolocator = Nominatim(user_agent="geoapi")
599
- location = geolocator.geocode(address)
600
- if location:
601
- lat, lon = location.latitude, location.longitude
602
- else:
603
- st.error("Invalid address! Try again.")
 
 
 
 
 
 
 
 
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