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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -26
app.py CHANGED
@@ -589,31 +589,25 @@ elif option == "Symptom Checker":
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())
@@ -623,19 +617,25 @@ elif option == "Doctor Connect":
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
 
 
589
 
590
  elif option == "Doctor Connect":
591
  st.subheader("πŸ₯ Find a Doctor Near You")
592
+
593
+ st.markdown("**πŸ”Ή We'll try to detect your location automatically. You can also enter it manually if needed.**")
594
+
595
+ auto_lat, auto_lon = get_user_location()
596
+ use_manual = False
597
+
598
+ if auto_lat and auto_lon:
599
+ st.success(f"πŸ“ Auto-detected Location: Latitude {auto_lat}, Longitude {auto_lon}")
600
+ use_manual = st.checkbox("Is this incorrect? Click here to enter location manually.")
 
 
 
 
 
 
 
 
 
 
 
601
  else:
602
+ st.warning("⚠️ Could not auto-detect your location.")
603
+ use_manual = True
604
+
605
+ if use_manual:
606
+ manual_input = st.text_input("Enter your location (City, State or Latitude, Longitude):")
607
  if manual_input:
608
  geolocator = Nominatim(user_agent="geoapi")
609
  try:
610
+ # Handle input as coordinates if comma is found
611
  if "," in manual_input:
612
  parts = manual_input.split(",")
613
  lat = float(parts[0].strip())
 
617
  if location:
618
  lat, lon = location.latitude, location.longitude
619
  else:
620
+ st.error("❌ Invalid location entered.")
621
+ lat, lon = None, None
622
  except:
623
+ st.error("❌ Error parsing location input.")
624
+ lat, lon = None, None
625
+ else:
626
+ lat, lon = None, None
627
+ else:
628
+ lat, lon = auto_lat, auto_lon
629
+
630
  if lat and lon:
631
+ st.success(f"πŸ“Œ Final Location: Latitude {lat}, Longitude {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
  folium_static(map_)
635
 
636
 
637
 
638
+
639
  # elif option == "Doctor Connect":
640
  # st.subheader("πŸ“ Doctor Connect - Find Nearby Hospitals")
641