Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -145,63 +145,67 @@ def get_health_professionals_and_map(current_location, health_professional_query
|
|
| 145 |
def generate_suggestions(emotion):
|
| 146 |
suggestions = {
|
| 147 |
'joy': [
|
| 148 |
-
{"Title": "Relaxation Techniques", "Subject": "Relaxation", "Link": "https://www.helpguide.org/mental-health/meditation/mindful-breathing-meditation"},
|
| 149 |
-
{"Title": "Dealing with Stress", "Subject": "Stress Management", "Link": "https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety"},
|
| 150 |
-
{"Title": "Emotional Wellness Toolkit", "Subject": "Wellness", "Link": "https://www.nih.gov/health-information/emotional-wellness-toolkit"},
|
| 151 |
-
{"Title": "Relaxation Video", "Subject": "Video", "Link": "https://youtu.be/m1vaUGtyo-A"}
|
| 152 |
],
|
| 153 |
'anger': [
|
| 154 |
-
{"Title": "Emotional Wellness Toolkit", "Subject": "Wellness", "Link": "https://www.nih.gov/health-information/emotional-wellness-toolkit"},
|
| 155 |
-
{"Title": "Stress Management Tips", "Subject": "Stress Management", "Link": "https://www.health.harvard.edu/health-a-to-z"},
|
| 156 |
-
{"Title": "Dealing with Anger", "Subject": "Anger Management", "Link": "https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety"},
|
| 157 |
-
{"Title": "Relaxation Video", "Subject": "Video", "Link": "https://youtu.be/MIc299Flibs"}
|
| 158 |
],
|
| 159 |
'fear': [
|
| 160 |
-
{"Title": "Mindfulness Practices", "Subject": "Mindfulness", "Link": "https://www.helpguide.org/mental-health/meditation/mindful-breathing-meditation"},
|
| 161 |
-
{"Title": "Coping with Anxiety", "Subject": "Anxiety Management", "Link": "https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety"},
|
| 162 |
-
{"Title": "Emotional Wellness Toolkit", "Subject": "Wellness", "Link": "https://www.nih.gov/health-information/emotional-wellness-toolkit"},
|
| 163 |
-
{"Title": "Relaxation Video", "Subject": "Video", "Link": "https://youtu.be/yGKKz185M5o"}
|
| 164 |
],
|
| 165 |
'sadness': [
|
| 166 |
-
{"Title": "Emotional Wellness Toolkit", "Subject": "Wellness", "Link": "https://www.nih.gov/health-information/emotional-wellness-toolkit"},
|
| 167 |
-
{"Title": "Dealing with Anxiety", "Subject": "Anxiety Management", "Link": "https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety"},
|
| 168 |
-
{"Title": "Relaxation Video", "Subject": "Video", "Link": "https://youtu.be/-e-4Kx5px_I"}
|
| 169 |
],
|
| 170 |
'surprise': [
|
| 171 |
-
{"Title": "Managing Stress", "Subject": "Stress Management", "Link": "https://www.health.harvard.edu/health-a-to-z"},
|
| 172 |
-
{"Title": "Coping Strategies", "Subject": "Coping", "Link": "https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety"},
|
| 173 |
-
{"Title": "Relaxation Video", "Subject": "Video", "Link": "https://youtu.be/m1vaUGtyo-A"}
|
| 174 |
]
|
| 175 |
}
|
| 176 |
-
|
|
|
|
| 177 |
|
| 178 |
# Gradio interface
|
| 179 |
def gradio_app(message, location, health_query, submit_button, history, state):
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
|
|
|
|
|
|
|
|
|
| 199 |
|
| 200 |
# Gradio UI components
|
| 201 |
message_input = gr.Textbox(lines=1, label="Message")
|
| 202 |
location_input = gr.Textbox(value="Honolulu, HI", label="Current Location")
|
| 203 |
health_query_input = gr.Textbox(value="doctor", label="Health Professional Query (e.g., doctor, psychiatrist, psychologist)")
|
| 204 |
-
submit_button = gr.Button("Submit")
|
| 205 |
|
| 206 |
# Updated chat history component with 'messages' type
|
| 207 |
chat_history = gr.Chatbot(label="Well-Being Chat History", type='messages')
|
|
@@ -219,9 +223,9 @@ iface = gr.Interface(
|
|
| 219 |
inputs=[message_input, location_input, health_query_input, submit_button, gr.State()],
|
| 220 |
outputs=[chat_history, sentiment_output, emotion_output, route_info_output, map_output, suggestions_output, gr.State()],
|
| 221 |
allow_flagging="never",
|
| 222 |
-
live=
|
| 223 |
title="Well-Being App: Support, Sentiment, Emotion Detection & Health Professional Search"
|
| 224 |
)
|
| 225 |
|
| 226 |
# Launch the Gradio interface
|
| 227 |
-
iface.launch()
|
|
|
|
| 145 |
def generate_suggestions(emotion):
|
| 146 |
suggestions = {
|
| 147 |
'joy': [
|
| 148 |
+
{"Title": "Relaxation Techniques", "Subject": "Relaxation", "Link": '<a href="https://www.helpguide.org/mental-health/meditation/mindful-breathing-meditation" target="_blank">Mindful Breathing Meditation</a>'},
|
| 149 |
+
{"Title": "Dealing with Stress", "Subject": "Stress Management", "Link": '<a href="https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety" target="_blank">Tips for Dealing with Anxiety</a>'},
|
| 150 |
+
{"Title": "Emotional Wellness Toolkit", "Subject": "Wellness", "Link": '<a href="https://www.nih.gov/health-information/emotional-wellness-toolkit" target="_blank">Emotional Wellness Toolkit</a>'},
|
| 151 |
+
{"Title": "Relaxation Video", "Subject": "Video", "Link": '<a href="https://youtu.be/m1vaUGtyo-A" target="_blank">Watch Video</a>'}
|
| 152 |
],
|
| 153 |
'anger': [
|
| 154 |
+
{"Title": "Emotional Wellness Toolkit", "Subject": "Wellness", "Link": '<a href="https://www.nih.gov/health-information/emotional-wellness-toolkit" target="_blank">Emotional Wellness Toolkit</a>'},
|
| 155 |
+
{"Title": "Stress Management Tips", "Subject": "Stress Management", "Link": '<a href="https://www.health.harvard.edu/health-a-to-z" target="_blank">Harvard Health: Stress Management</a>'},
|
| 156 |
+
{"Title": "Dealing with Anger", "Subject": "Anger Management", "Link": '<a href="https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety" target="_blank">Tips for Dealing with Anger</a>'},
|
| 157 |
+
{"Title": "Relaxation Video", "Subject": "Video", "Link": '<a href="https://youtu.be/MIc299Flibs" target="_blank">Watch Video</a>'}
|
| 158 |
],
|
| 159 |
'fear': [
|
| 160 |
+
{"Title": "Mindfulness Practices", "Subject": "Mindfulness", "Link": '<a href="https://www.helpguide.org/mental-health/meditation/mindful-breathing-meditation" target="_blank">Mindful Breathing Meditation</a>'},
|
| 161 |
+
{"Title": "Coping with Anxiety", "Subject": "Anxiety Management", "Link": '<a href="https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety" target="_blank">Tips for Dealing with Anxiety</a>'},
|
| 162 |
+
{"Title": "Emotional Wellness Toolkit", "Subject": "Wellness", "Link": '<a href="https://www.nih.gov/health-information/emotional-wellness-toolkit" target="_blank">Emotional Wellness Toolkit</a>'},
|
| 163 |
+
{"Title": "Relaxation Video", "Subject": "Video", "Link": '<a href="https://youtu.be/yGKKz185M5o" target="_blank">Watch Video</a>'}
|
| 164 |
],
|
| 165 |
'sadness': [
|
| 166 |
+
{"Title": "Emotional Wellness Toolkit", "Subject": "Wellness", "Link": '<a href="https://www.nih.gov/health-information/emotional-wellness-toolkit" target="_blank">Emotional Wellness Toolkit</a>'},
|
| 167 |
+
{"Title": "Dealing with Anxiety", "Subject": "Anxiety Management", "Link": '<a href="https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety" target="_blank">Tips for Dealing with Anxiety</a>'},
|
| 168 |
+
{"Title": "Relaxation Video", "Subject": "Video", "Link": '<a href="https://youtu.be/-e-4Kx5px_I" target="_blank">Watch Video</a>'}
|
| 169 |
],
|
| 170 |
'surprise': [
|
| 171 |
+
{"Title": "Managing Stress", "Subject": "Stress Management", "Link": '<a href="https://www.health.harvard.edu/health-a-to-z" target="_blank">Harvard Health: Stress Management</a>'},
|
| 172 |
+
{"Title": "Coping Strategies", "Subject": "Coping", "Link": '<a href="https://www.helpguide.org/mental-health/anxiety/tips-for-dealing-with-anxiety" target="_blank">Coping with Anxiety</a>'},
|
| 173 |
+
{"Title": "Relaxation Video", "Subject": "Video", "Link": '<a href="https://youtu.be/m1vaUGtyo-A" target="_blank">Watch Video</a>'}
|
| 174 |
]
|
| 175 |
}
|
| 176 |
+
|
| 177 |
+
return suggestions.get(emotion, [])
|
| 178 |
|
| 179 |
# Gradio interface
|
| 180 |
def gradio_app(message, location, health_query, submit_button, history, state):
|
| 181 |
+
if submit_button:
|
| 182 |
+
# Chatbot interaction
|
| 183 |
+
history, _ = chatbot(message, history)
|
| 184 |
+
|
| 185 |
+
# Sentiment analysis
|
| 186 |
+
sentiment_response = analyze_sentiment(message)
|
| 187 |
+
|
| 188 |
+
# Emotion detection
|
| 189 |
+
emotion_response = detect_emotion(message)
|
| 190 |
+
|
| 191 |
+
# Health professional search and map display
|
| 192 |
+
route_info, map_html = get_health_professionals_and_map(location, health_query)
|
| 193 |
+
|
| 194 |
+
# Generate suggestions based on the detected emotion
|
| 195 |
+
suggestions = generate_suggestions(emotion_response.split(': ')[1])
|
| 196 |
+
|
| 197 |
+
# Create a DataFrame for displaying suggestions
|
| 198 |
+
suggestions_df = pd.DataFrame(suggestions)
|
| 199 |
+
|
| 200 |
+
return history, sentiment_response, emotion_response, route_info, map_html, gr.DataFrame(suggestions_df, headers=["Title", "Subject", "Link"]), state
|
| 201 |
+
else:
|
| 202 |
+
return history, "", "", "", "", gr.DataFrame([], headers=["Title", "Subject", "Link"]), state
|
| 203 |
|
| 204 |
# Gradio UI components
|
| 205 |
message_input = gr.Textbox(lines=1, label="Message")
|
| 206 |
location_input = gr.Textbox(value="Honolulu, HI", label="Current Location")
|
| 207 |
health_query_input = gr.Textbox(value="doctor", label="Health Professional Query (e.g., doctor, psychiatrist, psychologist)")
|
| 208 |
+
submit_button = gr.Button("Submit")
|
| 209 |
|
| 210 |
# Updated chat history component with 'messages' type
|
| 211 |
chat_history = gr.Chatbot(label="Well-Being Chat History", type='messages')
|
|
|
|
| 223 |
inputs=[message_input, location_input, health_query_input, submit_button, gr.State()],
|
| 224 |
outputs=[chat_history, sentiment_output, emotion_output, route_info_output, map_output, suggestions_output, gr.State()],
|
| 225 |
allow_flagging="never",
|
| 226 |
+
live=False,
|
| 227 |
title="Well-Being App: Support, Sentiment, Emotion Detection & Health Professional Search"
|
| 228 |
)
|
| 229 |
|
| 230 |
# Launch the Gradio interface
|
| 231 |
+
iface.launch()
|