DreamStream-1 commited on
Commit
4705f7f
·
verified ·
1 Parent(s): 4c8161e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -13
app.py CHANGED
@@ -137,7 +137,7 @@ def get_health_professionals_and_map(location, query):
137
  """Search nearby healthcare professionals using Google Maps API."""
138
  try:
139
  if not location or not query:
140
- return ["Please provide both location and query."], ""
141
 
142
  geo_location = gmaps.geocode(location)
143
  if geo_location:
@@ -146,31 +146,40 @@ def get_health_professionals_and_map(location, query):
146
  professionals = []
147
  map_ = folium.Map(location=(lat, lng), zoom_start=13)
148
  for place in places_result:
149
- professionals.append(f"{place['name']} - {place.get('vicinity', 'No address provided')}")
 
 
 
150
  folium.Marker(
151
  location=[place["geometry"]["location"]["lat"], place["geometry"]["location"]["lng"]],
152
  popup=f"{place['name']}"
153
  ).add_to(map_)
154
- return professionals, map_._repr_html_()
155
 
156
- return ["No professionals found for the given location."], ""
157
  except Exception as e:
158
- return [f"An error occurred: {e}"], ""
159
 
160
- # Main Application Logic
161
  def app_function(user_input, location, query, history):
 
162
  chatbot_history, _ = generate_chatbot_response(user_input, history)
163
  sentiment_result = analyze_sentiment(user_input)
164
  emotion_result, cleaned_emotion = detect_emotion(user_input)
165
  suggestions = generate_suggestions(cleaned_emotion)
166
- professionals, map_html = get_health_professionals_and_map(location, query)
167
- return chatbot_history, sentiment_result, emotion_result, suggestions, professionals, map_html
 
 
 
 
 
 
168
 
169
  # CSS Styling
170
  custom_css = """
171
  body {
172
  font-family: 'Roboto', sans-serif;
173
- background: linear-gradient(135deg, #0d0d0d, #ff5722);
174
  color: white;
175
  }
176
 
@@ -240,11 +249,9 @@ with gr.Blocks(css=custom_css) as app:
240
  sentiment = gr.Textbox(label="Detected Sentiment")
241
  emotion = gr.Textbox(label="Detected Emotion")
242
 
243
- # Adding Suggestions Title with Styled Markdown (Centered and Bold)
244
  gr.Markdown("Suggestions", elem_id="suggestions-title")
245
-
246
  suggestions = gr.DataFrame(headers=["Title", "Link"]) # Table for suggestions
247
- professionals = gr.Textbox(label="Nearby Professionals", lines=6)
248
  map_html = gr.HTML(label="Interactive Map")
249
  submit = gr.Button(value="Submit", variant="primary")
250
 
@@ -254,4 +261,4 @@ with gr.Blocks(css=custom_css) as app:
254
  outputs=[chatbot, sentiment, emotion, suggestions, professionals, map_html],
255
  )
256
 
257
- app.launch()
 
137
  """Search nearby healthcare professionals using Google Maps API."""
138
  try:
139
  if not location or not query:
140
+ return [], "Please provide both location and query.", ""
141
 
142
  geo_location = gmaps.geocode(location)
143
  if geo_location:
 
146
  professionals = []
147
  map_ = folium.Map(location=(lat, lng), zoom_start=13)
148
  for place in places_result:
149
+ professionals.append({
150
+ "Name": place['name'],
151
+ "Address": place.get('vicinity', 'No address provided'),
152
+ })
153
  folium.Marker(
154
  location=[place["geometry"]["location"]["lat"], place["geometry"]["location"]["lng"]],
155
  popup=f"{place['name']}"
156
  ).add_to(map_)
157
+ return professionals, "", map_._repr_html_()
158
 
159
+ return [], "No professionals found for the given location.", ""
160
  except Exception as e:
161
+ return [], f"An error occurred: {e}", ""
162
 
 
163
  def app_function(user_input, location, query, history):
164
+ """Main application function to process inputs and return outputs."""
165
  chatbot_history, _ = generate_chatbot_response(user_input, history)
166
  sentiment_result = analyze_sentiment(user_input)
167
  emotion_result, cleaned_emotion = detect_emotion(user_input)
168
  suggestions = generate_suggestions(cleaned_emotion)
169
+
170
+ # Fetch professionals dynamically
171
+ professionals_data, error_message, map_html = get_health_professionals_and_map(location, query)
172
+
173
+ if error_message:
174
+ professionals_data = [{"Name": "Error", "Address": error_message}]
175
+
176
+ return chatbot_history, sentiment_result, emotion_result, suggestions, professionals_data, map_html
177
 
178
  # CSS Styling
179
  custom_css = """
180
  body {
181
  font-family: 'Roboto', sans-serif;
182
+ background: linear-gradient(135deg, #0f9d58, #34a853);
183
  color: white;
184
  }
185
 
 
249
  sentiment = gr.Textbox(label="Detected Sentiment")
250
  emotion = gr.Textbox(label="Detected Emotion")
251
 
 
252
  gr.Markdown("Suggestions", elem_id="suggestions-title")
 
253
  suggestions = gr.DataFrame(headers=["Title", "Link"]) # Table for suggestions
254
+ professionals = gr.DataFrame(headers=["Name", "Address"]) # Table for professionals
255
  map_html = gr.HTML(label="Interactive Map")
256
  submit = gr.Button(value="Submit", variant="primary")
257
 
 
261
  outputs=[chatbot, sentiment, emotion, suggestions, professionals, map_html],
262
  )
263
 
264
+ app.launch()