1
1
# Contact Feature
2
2
3
3
import streamlit as st
4
- from geopy .geocoders import Nominatim
4
+ import pandas as pd
5
+ import pydeck as pdk
5
6
import requests
6
7
7
8
st .set_page_config (
8
- page_title = "Skin Cancer " ,
9
+ page_title = "Diagnose " ,
9
10
page_icon = "♋" ,
10
11
layout = "centered" ,
11
12
initial_sidebar_state = "expanded" ,
12
13
)
13
14
14
- # Replace YOUR_API_KEY with your actual API key
15
- api_key = st .secrets ["api_key" ]
16
-
17
15
18
16
st .title ("Find a dermatologist" )
19
- # Set the location and radius for the search
17
+
18
+ # Create a function to search for nearby doctors based on city name
19
+ def search_doctors (city ):
20
+ # Google Maps API key
21
+ api_key = st .secrets ["API_KEY" ]
22
+ url = f"https://maps.googleapis.com/maps/api/place/textsearch/json?query=dermatologists+in+{ city } &key={ api_key } "
23
+ results = requests .get (url ).json ()
24
+ return results ["results" ]
25
+
26
+
27
+ # Input city name
20
28
city = st .text_input (
21
29
label = "Enter your city" ,
22
30
placeholder = "City (e.g. New Delhi)" ,
23
31
help = "Enter the name of the city where you want to find a dermatologist" ,
24
32
).strip ()
25
33
26
- if city != "" :
27
- # Create a geolocator object
28
- geolocator = Nominatim (user_agent = "skin_cancer" )
29
-
30
- # Use the geolocator to get the latitude and longitude of the city
31
- location = geolocator .geocode (city )
32
- latitude = location .latitude
33
- longitude = location .longitude
34
-
35
- location = f"{ latitude } ,{ longitude } "
36
- radius = 10000 # 10 km
37
- keyword = "dermatologist"
38
-
39
- # Make the request to the Places API
40
- url = f"https://maps.googleapis.com/maps/api/place/nearbysearch/json?location={ location } &radius={ radius } &keyword={ keyword } &key={ api_key } "
41
- response = requests .get (url )
42
- results = response .json ()["results" ]
43
-
44
- # Extract the place IDs of the results
45
- place_ids = [result ["place_id" ] for result in results ]
34
+ if city :
35
+ # Search for nearby doctors
36
+ doctors = search_doctors (city )
46
37
47
- # Use the place IDs to get the details of the places
48
- dermatologists = []
49
- for place_id in place_ids :
50
- url = f"https://maps.googleapis.com/maps/api/place/details/json?place_id={ place_id } &key={ api_key } "
51
- response = requests .get (url )
52
- place_details = response .json ()["result" ]
53
- dermatologists .append (
54
- {
55
- "name" : place_details ["name" ],
56
- "address" : place_details ["formatted_address" ],
57
- }
38
+ # Display the results to the user
39
+ st .write ("Results for Dermatologist doctors in: " , city )
40
+ lat_long = [
41
+ (doc ["geometry" ]["location" ]["lat" ], doc ["geometry" ]["location" ]["lng" ])
42
+ for doc in doctors
43
+ ]
44
+ df = pd .DataFrame (lat_long , columns = ["latitude" , "longitude" ])
45
+ st .pydeck_chart (
46
+ pdk .Deck (
47
+ map_style = "mapbox://styles/mapbox/streets-v12" ,
48
+ initial_view_state = pdk .ViewState (
49
+ latitude = df ["latitude" ].mean (),
50
+ longitude = df ["longitude" ].mean (),
51
+ zoom = 11 ,
52
+ pitch = 50 ,
53
+ ),
54
+ layers = [
55
+ pdk .Layer (
56
+ "ScatterplotLayer" ,
57
+ data = df ,
58
+ get_position = ["longitude" , "latitude" ],
59
+ get_radius = 100 ,
60
+ get_color = [200 , 30 , 0 ],
61
+ pickable = True ,
62
+ auto_highlight = True ,
63
+ )
64
+ ],
58
65
)
66
+ )
59
67
60
- # Display the results in Streamlit
61
- st .header ("Results" )
62
- for i , dermatologist in enumerate (dermatologists , start = 1 ):
63
- # st.markdown(f"**{dermatologist['name']}**")
64
- # st.markdown(dermatologist["address"])
65
- st .markdown (
66
- f"""
67
- { i } . **{ dermatologist ['name' ]} **
68
- > **Address:** { dermatologist ['address' ]}
69
- """
70
- )
68
+ for i , doctor in enumerate (doctors ):
69
+ st .write (f"{ i + 1 } . **Name**: " , doctor ["name" ])
70
+ st .write ("> **Address**: " , doctor ["formatted_address" ])
0 commit comments