Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -36,7 +36,10 @@ def get_route_and_medical_centers(current_location, destination_location, health
|
|
36 |
m = None # Default to None
|
37 |
|
38 |
# Fetch the directions for the route
|
39 |
-
|
|
|
|
|
|
|
40 |
|
41 |
if steps and coords:
|
42 |
route_info = [f"{i+1}. {step['html_instructions']}" for i, step in enumerate(steps)]
|
@@ -47,45 +50,51 @@ def get_route_and_medical_centers(current_location, destination_location, health
|
|
47 |
|
48 |
# Fetch nearby medical centers if the location input is provided
|
49 |
if current_location and health_professional_query:
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
66 |
else:
|
67 |
-
route_info += "\
|
68 |
-
|
69 |
-
route_info += "\
|
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=
|
89 |
)
|
90 |
|
91 |
# Launch Gradio interface
|
|
|
36 |
m = None # Default to None
|
37 |
|
38 |
# Fetch the directions for the route
|
39 |
+
try:
|
40 |
+
steps, coords = get_directions_and_coords(current_location, destination_location)
|
41 |
+
except Exception as e:
|
42 |
+
return f"Error fetching directions: {str(e)}", None
|
43 |
|
44 |
if steps and coords:
|
45 |
route_info = [f"{i+1}. {step['html_instructions']}" for i, step in enumerate(steps)]
|
|
|
50 |
|
51 |
# Fetch nearby medical centers if the location input is provided
|
52 |
if current_location and health_professional_query:
|
53 |
+
try:
|
54 |
+
# Fetch the coordinates of the current location using Google Geocoding
|
55 |
+
geocode_result = gmaps.geocode(current_location)
|
56 |
+
if geocode_result:
|
57 |
+
location_coords = geocode_result[0]['geometry']['location']
|
58 |
+
lat, lon = location_coords['lat'], location_coords['lng']
|
59 |
+
|
60 |
+
# Fetch nearby medical centers based on the query
|
61 |
+
medical_centers = search_medical_centers(health_professional_query, (lat, lon))
|
62 |
+
|
63 |
+
if medical_centers:
|
64 |
+
for center in medical_centers:
|
65 |
+
name = center['name']
|
66 |
+
vicinity = center.get('vicinity', 'N/A')
|
67 |
+
rating = center.get('rating', 'N/A')
|
68 |
+
folium.Marker([center['geometry']['location']['lat'], center['geometry']['location']['lng']],
|
69 |
+
popup=f"{name}\n{vicinity}\nRating: {rating}").add_to(m)
|
70 |
+
else:
|
71 |
+
route_info += "\nNo medical centers found matching your query."
|
72 |
else:
|
73 |
+
route_info += "\nCould not retrieve location coordinates."
|
74 |
+
except Exception as e:
|
75 |
+
route_info += f"\nError fetching medical centers: {str(e)}"
|
76 |
|
77 |
# Return both the route info and the map
|
78 |
return "\n".join(route_info), m._repr_html_()
|
79 |
|
80 |
# Gradio UI components (Updated for Gradio v3.x)
|
81 |
+
current_location_input = gr.Textbox(value="Honolulu, HI", label="Current Location (Plain Text)")
|
82 |
+
destination_location_input = gr.Textbox(value="Maui, HI", label="Destination Location (Plain Text)")
|
83 |
+
health_professional_query_input = gr.Textbox(value="Hawaii Medical Center", label="Health Professional Query (Plain Text)")
|
84 |
|
85 |
# Output components (Updated for Gradio v3.x)
|
86 |
route_info_output = gr.Textbox(label="Driving Directions")
|
87 |
map_output = gr.HTML(label="Map with Route and Health Professionals")
|
88 |
|
89 |
+
# Submit button
|
90 |
+
submit_button = gr.Button("Submit")
|
91 |
+
|
92 |
# Create Gradio interface
|
93 |
iface = gr.Interface(
|
94 |
fn=get_route_and_medical_centers, # Function to call
|
95 |
+
inputs=[current_location_input, destination_location_input, health_professional_query_input, submit_button], # Inputs
|
96 |
outputs=[route_info_output, map_output], # Outputs
|
97 |
+
live=False # Disable live updates, use button click to trigger the function
|
98 |
)
|
99 |
|
100 |
# Launch Gradio interface
|