Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -75,7 +75,10 @@ def chatbot(message, history):
|
|
| 75 |
except Exception as e:
|
| 76 |
response = f"An error occurred: {str(e)}"
|
| 77 |
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
| 79 |
return history, history
|
| 80 |
|
| 81 |
# Sentiment Analysis using Hugging Face model
|
|
@@ -110,78 +113,11 @@ def search_health_professionals(query, location, radius=10000):
|
|
| 110 |
|
| 111 |
# Function to get directions and display on Gradio UI
|
| 112 |
def get_health_professionals_and_map(current_location, health_professional_query):
|
| 113 |
-
|
| 114 |
-
m = None # Default to None
|
| 115 |
-
try:
|
| 116 |
-
# Geocode the current location (i.e., convert it to latitude and longitude)
|
| 117 |
-
geocode_result = gmaps.geocode(current_location)
|
| 118 |
-
if not geocode_result:
|
| 119 |
-
route_info = "Could not retrieve location coordinates. Please enter a valid location."
|
| 120 |
-
return route_info, m
|
| 121 |
-
|
| 122 |
-
location_coords = geocode_result[0]['geometry']['location']
|
| 123 |
-
lat, lon = location_coords['lat'], location_coords['lng']
|
| 124 |
-
|
| 125 |
-
# Search for health professionals
|
| 126 |
-
health_professionals = search_health_professionals(health_professional_query, (lat, lon))
|
| 127 |
-
|
| 128 |
-
if health_professionals:
|
| 129 |
-
route_info = "Health professionals found:\n"
|
| 130 |
-
m = folium.Map(location=[lat, lon], zoom_start=12)
|
| 131 |
-
for professional in health_professionals:
|
| 132 |
-
name = professional['name']
|
| 133 |
-
vicinity = professional.get('vicinity', 'N/A')
|
| 134 |
-
rating = professional.get('rating', 'N/A')
|
| 135 |
-
folium.Marker([professional['geometry']['location']['lat'], professional['geometry']['location']['lng']],
|
| 136 |
-
popup=f"{name}\n{vicinity}\nRating: {rating}").add_to(m)
|
| 137 |
-
route_info += f"- {name} ({rating} stars): {vicinity}\n"
|
| 138 |
-
else:
|
| 139 |
-
route_info = "No health professionals found matching your query."
|
| 140 |
-
m = folium.Map(location=[lat, lon], zoom_start=12) # Default map if no professionals are found
|
| 141 |
-
|
| 142 |
-
except Exception as e:
|
| 143 |
-
route_info = f"Error: {str(e)}"
|
| 144 |
-
m = folium.Map(location=[20, 0], zoom_start=2) # Default map if any error occurs
|
| 145 |
-
|
| 146 |
-
return route_info, m._repr_html_()
|
| 147 |
|
| 148 |
# Function to generate suggestions based on the detected emotion
|
| 149 |
def generate_suggestions(emotion):
|
| 150 |
-
|
| 151 |
-
return [
|
| 152 |
-
{"Title": "Relaxation Techniques", "Subject": "Relaxation", "Link": "https://www.helpguide.org/mental-health/meditation/mindful-breathing-meditation"},
|
| 153 |
-
{"Title": "Dealing with Stress", "Subject": "Stress Management", "Link": "https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety"},
|
| 154 |
-
{"Title": "Emotional Wellness Toolkit", "Subject": "Wellness", "Link": "https://www.nih.gov/health-information/emotional-wellness-toolkit"},
|
| 155 |
-
{"Title": "Relaxation Video", "Subject": "Video", "Link": "https://youtu.be/m1vaUGtyo-A"}
|
| 156 |
-
]
|
| 157 |
-
elif emotion == 'anger':
|
| 158 |
-
return [
|
| 159 |
-
{"Title": "Emotional Wellness Toolkit", "Subject": "Wellness", "Link": "https://www.nih.gov/health-information/emotional-wellness-toolkit"},
|
| 160 |
-
{"Title": "Stress Management Tips", "Subject": "Stress Management", "Link": "https://www.health.harvard.edu/health-a-to-z"},
|
| 161 |
-
{"Title": "Dealing with Anger", "Subject": "Anger Management", "Link": "https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety"},
|
| 162 |
-
{"Title": "Relaxation Video", "Subject": "Video", "Link": "https://youtu.be/MIc299Flibs"}
|
| 163 |
-
]
|
| 164 |
-
elif emotion == 'fear':
|
| 165 |
-
return [
|
| 166 |
-
{"Title": "Mindfulness Practices", "Subject": "Mindfulness", "Link": "https://www.helpguide.org/mental-health/meditation/mindful-breathing-meditation"},
|
| 167 |
-
{"Title": "Coping with Anxiety", "Subject": "Anxiety Management", "Link": "https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety"},
|
| 168 |
-
{"Title": "Emotional Wellness Toolkit", "Subject": "Wellness", "Link": "https://www.nih.gov/health-information/emotional-wellness-toolkit"},
|
| 169 |
-
{"Title": "Relaxation Video", "Subject": "Video", "Link": "https://youtu.be/yGKKz185M5o"}
|
| 170 |
-
]
|
| 171 |
-
elif emotion == 'sadness':
|
| 172 |
-
return [
|
| 173 |
-
{"Title": "Emotional Wellness Toolkit", "Subject": "Wellness", "Link": "https://www.nih.gov/health-information/emotional-wellness-toolkit"},
|
| 174 |
-
{"Title": "Dealing with Anxiety", "Subject": "Anxiety Management", "Link": "https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety"},
|
| 175 |
-
{"Title": "Relaxation Video", "Subject": "Video", "Link": "https://youtu.be/-e-4Kx5px_I"}
|
| 176 |
-
]
|
| 177 |
-
elif emotion == 'surprise':
|
| 178 |
-
return [
|
| 179 |
-
{"Title": "Managing Stress", "Subject": "Stress Management", "Link": "https://www.health.harvard.edu/health-a-to-z"},
|
| 180 |
-
{"Title": "Coping Strategies", "Subject": "Coping", "Link": "https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety"},
|
| 181 |
-
{"Title": "Relaxation Video", "Subject": "Video", "Link": "https://youtu.be/m1vaUGtyo-A"}
|
| 182 |
-
]
|
| 183 |
-
else:
|
| 184 |
-
return []
|
| 185 |
|
| 186 |
# Gradio interface
|
| 187 |
def gradio_app(message, location, health_query, submit_button, history, state):
|
|
|
|
| 75 |
except Exception as e:
|
| 76 |
response = f"An error occurred: {str(e)}"
|
| 77 |
|
| 78 |
+
# Convert the new message and response to the 'messages' format
|
| 79 |
+
history.append({"role": "user", "content": message})
|
| 80 |
+
history.append({"role": "assistant", "content": response})
|
| 81 |
+
|
| 82 |
return history, history
|
| 83 |
|
| 84 |
# Sentiment Analysis using Hugging Face model
|
|
|
|
| 113 |
|
| 114 |
# Function to get directions and display on Gradio UI
|
| 115 |
def get_health_professionals_and_map(current_location, health_professional_query):
|
| 116 |
+
# ... (Your function definition remains unchanged)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
# Function to generate suggestions based on the detected emotion
|
| 119 |
def generate_suggestions(emotion):
|
| 120 |
+
# ... (Your function definition remains unchanged)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
# Gradio interface
|
| 123 |
def gradio_app(message, location, health_query, submit_button, history, state):
|