MayankGupta06 commited on
Commit
58cb9c0
Β·
verified Β·
1 Parent(s): 2df683c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -39
app.py CHANGED
@@ -490,7 +490,6 @@ st.markdown("πŸ”Ή Powered by Mayank, Wasim, Pravishank – Innovating Healthcare
490
 
491
 
492
 
493
- '''
494
  import streamlit as st
495
  import speech_recognition as sr
496
  from deep_translator import GoogleTranslator
@@ -527,6 +526,15 @@ st.sidebar.title("πŸ” Navigation")
527
  option = st.sidebar.radio("Select an option:", ["Home", "Symptom Checker", "Doctor Connect", "Health Stats"])
528
  translator = GoogleTranslator(source='auto', target='en')
529
 
 
 
 
 
 
 
 
 
 
530
  if option == "Home":
531
  user_question = st.text_input("Type your symptoms or disease name:")
532
 
@@ -571,50 +579,73 @@ elif option == "Symptom Checker":
571
  response = llm.invoke(symptom_query)
572
  st.write(response.content if hasattr(response, "content") else str(response))
573
 
 
574
  elif option == "Doctor Connect":
575
- st.subheader("πŸ“ Doctor Connect - Find Nearby Hospitals")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
576
 
577
- def get_user_location():
578
- geolocator = Nominatim(user_agent="geoapi")
579
- location = geolocator.geocode("Phagwara") # Replace with dynamic location if needed
580
- if location:
581
- return location.latitude, location.longitude
582
- return None
583
 
584
- def find_nearby_hospitals(user_location):
585
- hospitals = [
586
- {"name": "Apollo Hospital", "location": (30.7333, 76.7794)},
587
- {"name": "Fortis Hospital", "location": (30.7194, 76.7644)},
588
- {"name": "Max Hospital", "location": (30.7086, 76.7853)},
589
- {"name": "AIIMS Hospital", "location": (30.7500, 76.7800)}
590
- ]
591
 
592
- nearby_hospitals = []
593
- for hospital in hospitals:
594
- distance = geodesic(user_location, hospital["location"]).km
595
- if distance <= 10:
596
- nearby_hospitals.append(hospital)
597
- return nearby_hospitals
598
 
599
- user_location = get_user_location()
600
- if user_location:
601
- st.success(f"πŸ“ Your Location: {user_location}")
602
 
603
- m = folium.Map(location=user_location, zoom_start=13)
604
- folium.Marker(user_location, tooltip="Your Location", icon=folium.Icon(color="blue")).add_to(m)
605
 
606
- hospitals = find_nearby_hospitals(user_location)
607
- if hospitals:
608
- st.write("πŸ₯ Nearby Hospitals:")
609
- for hospital in hospitals:
610
- st.write(f"πŸ”Ή {hospital['name']}")
611
- folium.Marker(hospital["location"], tooltip=hospital["name"], icon=folium.Icon(color="red")).add_to(m)
612
- else:
613
- st.write("⚠️ No nearby hospitals found within 10 km.")
614
 
615
- folium_static(m)
616
- else:
617
- st.error("⚠️ Unable to fetch location. Please allow location access or enter manually.")
618
 
619
  elif option == "Health Stats":
620
  st.subheader("πŸ“Š Health Trends & Data")
@@ -641,12 +672,11 @@ st.markdown("πŸ”Ή Powered by Mayank, Wasim, Pravishank – Innovating Healthcare
641
 
642
 
643
 
644
- '''
645
-
646
 
647
 
648
 
649
 
 
650
  import streamlit as st
651
  import speech_recognition as sr
652
  from deep_translator import GoogleTranslator
@@ -778,3 +808,4 @@ st.sidebar.write("- πŸš“ *Police:* 1000")
778
  st.markdown("---")
779
  st.markdown("πŸ”Ή Powered by Mayank, Wasim, Pravishank – Innovating Healthcare with AI! πŸ’‘ Your Health, Our Mission. πŸš€")
780
 
 
 
490
 
491
 
492
 
 
493
  import streamlit as st
494
  import speech_recognition as sr
495
  from deep_translator import GoogleTranslator
 
526
  option = st.sidebar.radio("Select an option:", ["Home", "Symptom Checker", "Doctor Connect", "Health Stats"])
527
  translator = GoogleTranslator(source='auto', target='en')
528
 
529
+ # Function to Get User Location
530
+ def get_user_location():
531
+ try:
532
+ response = requests.get("https://ipinfo.io/json").json()
533
+ location = response["loc"].split(",")
534
+ return float(location[0]), float(location[1])
535
+ except:
536
+ return None, None
537
+
538
  if option == "Home":
539
  user_question = st.text_input("Type your symptoms or disease name:")
540
 
 
579
  response = llm.invoke(symptom_query)
580
  st.write(response.content if hasattr(response, "content") else str(response))
581
 
582
+
583
  elif option == "Doctor Connect":
584
+ st.subheader("πŸ₯ Find a Doctor Near You")
585
+ lat, lon = get_user_location()
586
+
587
+ if lat is None or lon is None:
588
+ st.warning("Unable to fetch location. Please allow location access or enter manually.")
589
+ address = st.text_input("Enter your location (City, State or Latitude, Longitude):")
590
+ if address:
591
+ geolocator = Nominatim(user_agent="geoapi")
592
+ location = geolocator.geocode(address)
593
+ if location:
594
+ lat, lon = location.latitude, location.longitude
595
+ else:
596
+ st.error("Invalid address! Try again.")
597
+
598
+ if lat and lon:
599
+ st.success(f"πŸ“ Location detected: {lat}, {lon}")
600
+ map_ = folium.Map(location=[lat, lon], zoom_start=13)
601
+ folium.Marker([lat, lon], popup="You are here!", icon=folium.Icon(color="blue")).add_to(map_)
602
+ folium_static(map_)
603
+
604
+
605
+ # elif option == "Doctor Connect":
606
+ # st.subheader("πŸ“ Doctor Connect - Find Nearby Hospitals")
607
 
608
+ # def get_user_location():
609
+ # geolocator = Nominatim(user_agent="geoapi")
610
+ # location = geolocator.geocode("Phagwara") # Replace with dynamic location if needed
611
+ # if location:
612
+ # return location.latitude, location.longitude
613
+ # return None
614
 
615
+ # def find_nearby_hospitals(user_location):
616
+ # hospitals = [
617
+ # {"name": "Apollo Hospital", "location": (30.7333, 76.7794)},
618
+ # {"name": "Fortis Hospital", "location": (30.7194, 76.7644)},
619
+ # {"name": "Max Hospital", "location": (30.7086, 76.7853)},
620
+ # {"name": "AIIMS Hospital", "location": (30.7500, 76.7800)}
621
+ # ]
622
 
623
+ # nearby_hospitals = []
624
+ # for hospital in hospitals:
625
+ # distance = geodesic(user_location, hospital["location"]).km
626
+ # if distance <= 10:
627
+ # nearby_hospitals.append(hospital)
628
+ # return nearby_hospitals
629
 
630
+ # user_location = get_user_location()
631
+ # if user_location:
632
+ # st.success(f"πŸ“ Your Location: {user_location}")
633
 
634
+ # m = folium.Map(location=user_location, zoom_start=13)
635
+ # folium.Marker(user_location, tooltip="Your Location", icon=folium.Icon(color="blue")).add_to(m)
636
 
637
+ # hospitals = find_nearby_hospitals(user_location)
638
+ # if hospitals:
639
+ # st.write("πŸ₯ Nearby Hospitals:")
640
+ # for hospital in hospitals:
641
+ # st.write(f"πŸ”Ή {hospital['name']}")
642
+ # folium.Marker(hospital["location"], tooltip=hospital["name"], icon=folium.Icon(color="red")).add_to(m)
643
+ # else:
644
+ # st.write("⚠️ No nearby hospitals found within 10 km.")
645
 
646
+ # folium_static(m)
647
+ # else:
648
+ # st.error("⚠️ Unable to fetch location. Please allow location access or enter manually.")
649
 
650
  elif option == "Health Stats":
651
  st.subheader("πŸ“Š Health Trends & Data")
 
672
 
673
 
674
 
 
 
675
 
676
 
677
 
678
 
679
+ '''
680
  import streamlit as st
681
  import speech_recognition as sr
682
  from deep_translator import GoogleTranslator
 
808
  st.markdown("---")
809
  st.markdown("πŸ”Ή Powered by Mayank, Wasim, Pravishank – Innovating Healthcare with AI! πŸ’‘ Your Health, Our Mission. πŸš€")
810
 
811
+ '''