DreamStream-1 commited on
Commit
34d2572
·
verified ·
1 Parent(s): fd03b26

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -14
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(source_location, destination_location, medical_center_query, location_input):
 
 
 
35
  # Fetch the directions for the route
36
- steps, coords = get_directions_and_coords(source_location, destination_location)
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 location_input and medical_center_query:
47
- # Fetch the coordinates of the source location using Google Geocoding
48
- geocode_result = gmaps.geocode(location_input)
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(medical_center_query, (lat, lon))
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.append("No medical centers found matching your query.")
65
  else:
66
- route_info.append("Could not retrieve location coordinates.")
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
- source_location_input = gr.Textbox(value="Honolulu, HI", label="Source Location")
73
  destination_location_input = gr.Textbox(value="Maui, HI", label="Destination Location")
74
- medical_center_query_input = gr.Textbox(value="Hawaii Medical Center", label="Medical Center Query")
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 Medical Centers")
80
 
81
  # Create Gradio interface
82
  iface = gr.Interface(
83
  fn=get_route_and_medical_centers, # Function to call
84
- inputs=[source_location_input, destination_location_input, medical_center_query_input, location_input], # 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
  )