Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -31,9 +31,12 @@ def search_medical_centers(query, location, radius=10000):
|
|
31 |
return places_result.get('results', [])
|
32 |
|
33 |
# Function to get directions and display on Gradio UI
|
34 |
-
def get_route_and_medical_centers(
|
|
|
|
|
|
|
35 |
# Fetch the directions for the route
|
36 |
-
steps, coords = get_directions_and_coords(
|
37 |
|
38 |
if steps and coords:
|
39 |
route_info = [f"{i+1}. {step['html_instructions']}" for i, step in enumerate(steps)]
|
@@ -43,15 +46,15 @@ def get_route_and_medical_centers(source_location, destination_location, medical
|
|
43 |
m = folium.Map(location=[20, 0], zoom_start=2) # Default map if no route
|
44 |
|
45 |
# Fetch nearby medical centers if the location input is provided
|
46 |
-
if
|
47 |
-
# Fetch the coordinates of the
|
48 |
-
geocode_result = gmaps.geocode(
|
49 |
if geocode_result:
|
50 |
location_coords = geocode_result[0]['geometry']['location']
|
51 |
lat, lon = location_coords['lat'], location_coords['lng']
|
52 |
|
53 |
-
# Fetch nearby medical centers
|
54 |
-
medical_centers = search_medical_centers(
|
55 |
|
56 |
if medical_centers:
|
57 |
for center in medical_centers:
|
@@ -61,27 +64,26 @@ def get_route_and_medical_centers(source_location, destination_location, medical
|
|
61 |
folium.Marker([center['geometry']['location']['lat'], center['geometry']['location']['lng']],
|
62 |
popup=f"{name}\n{vicinity}\nRating: {rating}").add_to(m)
|
63 |
else:
|
64 |
-
route_info
|
65 |
else:
|
66 |
-
route_info
|
67 |
|
68 |
# Return both the route info and the map
|
69 |
return "\n".join(route_info), m._repr_html_()
|
70 |
|
71 |
# Gradio UI components (Updated for Gradio v3.x)
|
72 |
-
|
73 |
destination_location_input = gr.Textbox(value="Maui, HI", label="Destination Location")
|
74 |
-
|
75 |
-
location_input = gr.Textbox(value="Honolulu, HI", label="Your Location")
|
76 |
|
77 |
# Output components (Updated for Gradio v3.x)
|
78 |
route_info_output = gr.Textbox(label="Driving Directions")
|
79 |
-
map_output = gr.HTML(label="Map with Route and
|
80 |
|
81 |
# Create Gradio interface
|
82 |
iface = gr.Interface(
|
83 |
fn=get_route_and_medical_centers, # Function to call
|
84 |
-
inputs=[
|
85 |
outputs=[route_info_output, map_output], # Outputs
|
86 |
live=True # Update outputs live as inputs change
|
87 |
)
|
|
|
31 |
return places_result.get('results', [])
|
32 |
|
33 |
# Function to get directions and display on Gradio UI
|
34 |
+
def get_route_and_medical_centers(current_location, destination_location, health_professional_query):
|
35 |
+
route_info = ""
|
36 |
+
m = None # Default to None
|
37 |
+
|
38 |
# Fetch the directions for the route
|
39 |
+
steps, coords = get_directions_and_coords(current_location, destination_location)
|
40 |
|
41 |
if steps and coords:
|
42 |
route_info = [f"{i+1}. {step['html_instructions']}" for i, step in enumerate(steps)]
|
|
|
46 |
m = folium.Map(location=[20, 0], zoom_start=2) # Default map if no route
|
47 |
|
48 |
# Fetch nearby medical centers if the location input is provided
|
49 |
+
if current_location and health_professional_query:
|
50 |
+
# Fetch the coordinates of the current location using Google Geocoding
|
51 |
+
geocode_result = gmaps.geocode(current_location)
|
52 |
if geocode_result:
|
53 |
location_coords = geocode_result[0]['geometry']['location']
|
54 |
lat, lon = location_coords['lat'], location_coords['lng']
|
55 |
|
56 |
+
# Fetch nearby medical centers based on the query
|
57 |
+
medical_centers = search_medical_centers(health_professional_query, (lat, lon))
|
58 |
|
59 |
if medical_centers:
|
60 |
for center in medical_centers:
|
|
|
64 |
folium.Marker([center['geometry']['location']['lat'], center['geometry']['location']['lng']],
|
65 |
popup=f"{name}\n{vicinity}\nRating: {rating}").add_to(m)
|
66 |
else:
|
67 |
+
route_info += "\nNo medical centers found matching your query."
|
68 |
else:
|
69 |
+
route_info += "\nCould not retrieve location coordinates."
|
70 |
|
71 |
# Return both the route info and the map
|
72 |
return "\n".join(route_info), m._repr_html_()
|
73 |
|
74 |
# Gradio UI components (Updated for Gradio v3.x)
|
75 |
+
current_location_input = gr.Textbox(value="Honolulu, HI", label="Current Location")
|
76 |
destination_location_input = gr.Textbox(value="Maui, HI", label="Destination Location")
|
77 |
+
health_professional_query_input = gr.Textbox(value="Hawaii Medical Center", label="Health Professional Query")
|
|
|
78 |
|
79 |
# Output components (Updated for Gradio v3.x)
|
80 |
route_info_output = gr.Textbox(label="Driving Directions")
|
81 |
+
map_output = gr.HTML(label="Map with Route and Health Professionals")
|
82 |
|
83 |
# Create Gradio interface
|
84 |
iface = gr.Interface(
|
85 |
fn=get_route_and_medical_centers, # Function to call
|
86 |
+
inputs=[current_location_input, destination_location_input, health_professional_query_input], # Inputs
|
87 |
outputs=[route_info_output, map_output], # Outputs
|
88 |
live=True # Update outputs live as inputs change
|
89 |
)
|