DreamStream-1 commited on
Commit
b254705
·
verified ·
1 Parent(s): c2adf9a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -14
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,16 +146,19 @@ 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):
@@ -163,14 +166,16 @@ def app_function(user_input, location, query, 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
 
@@ -229,7 +234,7 @@ textarea:hover, input:hover {
229
  }
230
  """
231
 
232
- # Gradio Application
233
  with gr.Blocks(css=custom_css) as app:
234
  gr.HTML("<h1>🌟 Well-Being Companion</h1>")
235
  with gr.Row():
@@ -239,12 +244,9 @@ with gr.Blocks(css=custom_css) as app:
239
  chatbot = gr.Chatbot(label="Chat History")
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
 
 
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
  # Main Application Logic
164
  def app_function(user_input, location, query, history):
 
166
  sentiment_result = analyze_sentiment(user_input)
167
  emotion_result, cleaned_emotion = detect_emotion(user_input)
168
  suggestions = generate_suggestions(cleaned_emotion)
169
+ professionals, error_message, map_html = get_health_professionals_and_map(location, query)
170
+ if error_message:
171
+ professionals = [{"Message": error_message}]
172
  return chatbot_history, sentiment_result, emotion_result, suggestions, professionals, map_html
173
 
174
+ # CSS Styling (Updated)
175
  custom_css = """
176
  body {
177
  font-family: 'Roboto', sans-serif;
178
+ background: linear-gradient(135deg, #0f9d58, #34a853);
179
  color: white;
180
  }
181
 
 
234
  }
235
  """
236
 
237
+ # Gradio Application (Updated)
238
  with gr.Blocks(css=custom_css) as app:
239
  gr.HTML("<h1>🌟 Well-Being Companion</h1>")
240
  with gr.Row():
 
244
  chatbot = gr.Chatbot(label="Chat History")
245
  sentiment = gr.Textbox(label="Detected Sentiment")
246
  emotion = gr.Textbox(label="Detected Emotion")
 
 
247
  gr.Markdown("Suggestions", elem_id="suggestions-title")
248
+ suggestions = gr.DataFrame(headers=["Title", "Link"]) # Table for suggestions (two columns)
249
+ professionals = gr.DataFrame(headers=["Name", "Address"]) # Tabular display for professionals
 
250
  map_html = gr.HTML(label="Interactive Map")
251
  submit = gr.Button(value="Submit", variant="primary")
252