Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -111,8 +111,10 @@ def search_health_professionals(query, location, radius=10000):
|
|
111 |
|
112 |
# Function to get directions and display on Gradio UI
|
113 |
def get_health_professionals_and_map(current_location, health_professional_query):
|
114 |
-
|
115 |
-
|
|
|
|
|
116 |
lat = location[0]["geometry"]["location"]["lat"]
|
117 |
lng = location[0]["geometry"]["location"]["lng"]
|
118 |
location = (lat, lng)
|
@@ -137,8 +139,10 @@ def get_health_professionals_and_map(current_location, health_professional_query
|
|
137 |
route_info = "\n".join([f"{place['name']} - {place['vicinity']}" for place in professionals])
|
138 |
|
139 |
return route_info, map_html
|
140 |
-
|
141 |
-
return "
|
|
|
|
|
142 |
|
143 |
# Function to generate suggestions based on the detected emotion
|
144 |
def generate_suggestions(emotion):
|
@@ -175,67 +179,36 @@ css = """
|
|
175 |
background-color: #f7f7f7;
|
176 |
}
|
177 |
.gradio-input, .gradio-output {
|
178 |
-
|
179 |
-
border-radius: 5px;
|
180 |
-
background-color: #fff;
|
181 |
-
border: 1px solid #ccc;
|
182 |
}
|
183 |
-
.gradio-
|
184 |
-
background-color: #
|
185 |
color: white;
|
186 |
border-radius: 5px;
|
187 |
}
|
188 |
-
.gradio-
|
189 |
-
background-color: #
|
190 |
-
}
|
191 |
-
.gradio-output {
|
192 |
-
font-size: 16px;
|
193 |
-
color: #333;
|
194 |
-
}
|
195 |
-
.gradio-container h3 {
|
196 |
-
color: #333;
|
197 |
-
}
|
198 |
-
.gradio-output .output {
|
199 |
-
border-top: 2px solid #ddd;
|
200 |
}
|
201 |
"""
|
202 |
|
203 |
-
# Gradio interface
|
204 |
-
def gradio_app(message, current_location, health_professional_query, history):
|
205 |
-
# Detect sentiment and emotion
|
206 |
-
sentiment = analyze_sentiment(message)
|
207 |
-
emotion = detect_emotion(message)
|
208 |
-
|
209 |
-
# Generate suggestions based on emotion
|
210 |
-
suggestions_df = generate_suggestions(emotion)
|
211 |
-
|
212 |
-
# Get health professionals details and map
|
213 |
-
route_info, map_html = get_health_professionals_and_map(current_location, health_professional_query)
|
214 |
-
|
215 |
-
return sentiment, emotion, suggestions_df, route_info, map_html, history
|
216 |
-
|
217 |
-
# Gradio interface setup
|
218 |
iface = gr.Interface(
|
219 |
-
fn=
|
220 |
inputs=[
|
221 |
-
gr.Textbox(
|
222 |
-
gr.
|
223 |
-
gr.Textbox(lines=2, placeholder="Enter health professional query..."),
|
224 |
-
gr.State(value=[])
|
225 |
],
|
226 |
outputs=[
|
|
|
227 |
gr.Textbox(label="Sentiment Analysis"),
|
228 |
-
gr.Textbox(label="
|
229 |
-
gr.
|
230 |
-
gr.
|
231 |
-
gr.HTML(label="Map of Health Professionals"),
|
232 |
-
gr.State(value=[])
|
233 |
],
|
|
|
234 |
live=True,
|
235 |
-
|
236 |
-
theme="huggingface",
|
237 |
-
css=css # Apply custom CSS styling
|
238 |
)
|
239 |
|
240 |
-
# Launch Gradio interface
|
241 |
-
iface.launch(share=True)
|
|
|
111 |
|
112 |
# Function to get directions and display on Gradio UI
|
113 |
def get_health_professionals_and_map(current_location, health_professional_query):
|
114 |
+
try:
|
115 |
+
location = gmaps.geocode(current_location)
|
116 |
+
if not location:
|
117 |
+
return "Location not found. Please try again with a valid location.", ""
|
118 |
lat = location[0]["geometry"]["location"]["lat"]
|
119 |
lng = location[0]["geometry"]["location"]["lng"]
|
120 |
location = (lat, lng)
|
|
|
139 |
route_info = "\n".join([f"{place['name']} - {place['vicinity']}" for place in professionals])
|
140 |
|
141 |
return route_info, map_html
|
142 |
+
except googlemaps.exceptions.HTTPError as e:
|
143 |
+
return f"Error occurred with Google Maps API: {e}", ""
|
144 |
+
except Exception as e:
|
145 |
+
return f"Unexpected error: {str(e)}", ""
|
146 |
|
147 |
# Function to generate suggestions based on the detected emotion
|
148 |
def generate_suggestions(emotion):
|
|
|
179 |
background-color: #f7f7f7;
|
180 |
}
|
181 |
.gradio-input, .gradio-output {
|
182 |
+
font-size: 16px;
|
|
|
|
|
|
|
183 |
}
|
184 |
+
.gradio-button {
|
185 |
+
background-color: #FF5733;
|
186 |
color: white;
|
187 |
border-radius: 5px;
|
188 |
}
|
189 |
+
.gradio-button:hover {
|
190 |
+
background-color: #C70039;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
}
|
192 |
"""
|
193 |
|
194 |
+
# Gradio interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
iface = gr.Interface(
|
196 |
+
fn=chatbot,
|
197 |
inputs=[
|
198 |
+
gr.Textbox(label="Message", placeholder="Type a message...", lines=2),
|
199 |
+
gr.State()
|
|
|
|
|
200 |
],
|
201 |
outputs=[
|
202 |
+
gr.Chatbot(label="Chatbot History"),
|
203 |
gr.Textbox(label="Sentiment Analysis"),
|
204 |
+
gr.Textbox(label="Emotion Detection"),
|
205 |
+
gr.DataFrame(label="Suggestions Based on Emotion"),
|
206 |
+
gr.HTML(label="Health Professionals & Map")
|
|
|
|
|
207 |
],
|
208 |
+
layout="vertical",
|
209 |
live=True,
|
210 |
+
css=css
|
|
|
|
|
211 |
)
|
212 |
|
213 |
+
# Launch the Gradio interface
|
214 |
+
iface.launch(share=True)
|