DreamStream-1 commited on
Commit
4568d77
Β·
verified Β·
1 Parent(s): 756dc7b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -94
app.py CHANGED
@@ -11,7 +11,6 @@ from nltk.stem.lancaster import LancasterStemmer
11
  from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
12
  import googlemaps
13
  import folium
14
- import pandas as pd
15
  import torch
16
 
17
  # Disable GPU usage for TensorFlow
@@ -32,7 +31,7 @@ with open("data.pickle", "rb") as f:
32
  words, labels, training, output = pickle.load(f)
33
 
34
  # Build the model structure for Well-Being Chatbot
35
- net = tflearn.input_data(shape=[None, len(training[0])])
36
  net = tflearn.fully_connected(net, 8)
37
  net = tflearn.fully_connected(net, 8)
38
  net = tflearn.fully_connected(net, len(output[0]), activation="softmax")
@@ -152,99 +151,45 @@ def generate_suggestions(emotion):
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
- # Add more suggestions for other emotions as required...
 
 
 
 
 
 
 
 
 
 
 
160
  }
161
-
162
- return suggestions.get(emotion, [])
163
-
164
- # Custom CSS for green gradient background and button
165
- custom_css = """
166
- /* Gradient Background */
167
- body {
168
- background: linear-gradient(135deg, #00b894, #1dd1a1);
169
- font-family: Arial, sans-serif;
170
- color: white;
171
- box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.1), 0 0 30px rgba(0, 0, 0, 0.1);
172
- }
173
-
174
- /* Green gradient submit button */
175
- .gradio-button {
176
- background: linear-gradient(45deg, #00b894, #1dd1a1);
177
- border: none;
178
- color: white;
179
- font-weight: bold;
180
- font-size: 16px;
181
- padding: 10px 20px;
182
- border-radius: 10px;
183
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
184
- transition: background 0.3s ease, box-shadow 0.3s ease;
185
- }
186
-
187
- /* Hover effect for the submit button */
188
- .gradio-button:hover {
189
- background: linear-gradient(45deg, #1dd1a1, #00b894);
190
- box-shadow: 0 6px 10px rgba(0, 0, 0, 0.2);
191
- }
192
-
193
- /* Styling for the input box and other components */
194
- .gradio-input, .gradio-output, .gradio-chatbot {
195
- background: rgba(255, 255, 255, 0.1);
196
- border-radius: 8px;
197
- border: none;
198
- padding: 10px;
199
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
200
- }
201
-
202
- .gradio-input:focus {
203
- outline: none;
204
- background: rgba(255, 255, 255, 0.2);
205
- }
206
-
207
- /* Shadow effect on components */
208
- .gradio-box {
209
- box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
210
- }
211
- """
212
-
213
- # Gradio app code (as before)
214
- def gradio_app(message, location, health_query, history, state):
215
- # Chatbot interaction
216
- history, _ = chatbot(message, history)
217
-
218
- # Sentiment analysis
219
- sentiment_response = analyze_sentiment(message)
220
-
221
- # Emotion detection
222
- emotion_response = detect_emotion(message)
223
 
224
- # Health professional search and map display
225
- route_info, map_html = get_health_professionals_and_map(location, health_query)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
 
227
- # Generate suggestions based on the detected emotion
228
- suggestions = generate_suggestions(emotion_response.split(': ')[1])
229
-
230
- # Create a DataFrame for displaying suggestions
231
- suggestions_df = pd.DataFrame(suggestions)
232
-
233
- return history, sentiment_response, emotion_response, route_info, map_html, gr.DataFrame(suggestions_df, headers=["Title", "Subject", "Link"]), state
234
-
235
- # Gradio UI components
236
- message_input = gr.Textbox(lines=1, label="πŸ’¬ Message")
237
- location_input = gr.Textbox(value="Honolulu, HI", lines=1, label="πŸ“ Your Location")
238
- health_query_input = gr.Textbox(value="psychologist", lines=1, label="πŸ‘©β€βš•οΈ Health Professional Query")
239
- history_output = gr.Chatbot()
240
- sentiment_output = gr.Textbox()
241
- emotion_output = gr.Textbox()
242
- route_info_output = gr.Textbox()
243
- map_output = gr.HTML()
244
- suggestions_output = gr.DataFrame()
245
-
246
- # Interface with custom CSS
247
- gr.Interface(fn=gradio_app, inputs=[message_input, location_input, health_query_input, history_output, gr.State()],
248
- outputs=[history_output, sentiment_output, emotion_output, route_info_output, map_output, suggestions_output],
249
- live=True,
250
- css=custom_css).launch()
 
11
  from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
12
  import googlemaps
13
  import folium
 
14
  import torch
15
 
16
  # Disable GPU usage for TensorFlow
 
31
  words, labels, training, output = pickle.load(f)
32
 
33
  # Build the model structure for Well-Being Chatbot
34
+ net = tflearn.input_data(shape=[None, len(training[0])], dtype=tf.float32) # Fix for dtype
35
  net = tflearn.fully_connected(net, 8)
36
  net = tflearn.fully_connected(net, 8)
37
  net = tflearn.fully_connected(net, len(output[0]), activation="softmax")
 
151
  ],
152
  'anger': [
153
  {"Title": "Emotional Wellness Toolkit πŸ’‘", "Subject": "Wellness", "Link": '<a href="https://www.nih.gov/health-information/emotional-wellness-toolkit" target="_blank">Emotional Wellness Toolkit</a>'},
154
+ {"Title": "Managing Anger 🌿", "Subject": "Anger Management", "Link": '<a href="https://www.helpguide.org/mental-health/anger-management.htm" target="_blank">HelpGuide on Anger Management</a>'},
155
+ {"Title": "Relaxation Techniques πŸ’†", "Subject": "Relaxation", "Link": '<a href="https://www.helpguide.org/mental-health/meditation/mindful-breathing-meditation" target="_blank">Mindful Breathing Meditation</a>'},
156
+ {"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>'}
157
  ],
158
+ 'sadness': [
159
+ {"Title": "Overcoming Sadness 🌈", "Subject": "Well-being", "Link": '<a href="https://www.helpguide.org/mental-health/depression.htm" target="_blank">Overcoming Sadness</a>'},
160
+ {"Title": "Self-care Practices 🌿", "Subject": "Self-care", "Link": '<a href="https://www.psychologytoday.com/us/blog/pieces-mind/201908/self-care-for-your-mental-health" target="_blank">Self-Care for Mental Health</a>'},
161
+ {"Title": "Managing Grief πŸ’", "Subject": "Grief Management", "Link": '<a href="https://www.helpguide.org/mental-health/grief.htm" target="_blank">HelpGuide on Grief</a>'},
162
+ {"Title": "Mindfulness & Meditation πŸ’†", "Subject": "Meditation", "Link": '<a href="https://www.meditationandmindfulness.com" target="_blank">Mindfulness & Meditation</a>'}
163
+ ],
164
+ 'fear': [
165
+ {"Title": "Managing Fear & Anxiety πŸ’‘", "Subject": "Mental Health", "Link": '<a href="https://www.psychologytoday.com/us/articles/anxiety" target="_blank">Psychology Today on Anxiety</a>'},
166
+ {"Title": "Building Confidence πŸ’ͺ", "Subject": "Self-Confidence", "Link": '<a href="https://www.helpguide.org/mental-health/self-confidence.htm" target="_blank">Self-Confidence Guide</a>'},
167
+ {"Title": "Breathing Exercises πŸ§˜β€β™€οΈ", "Subject": "Breathing", "Link": '<a href="https://www.helpguide.org/mental-health/meditation/mindful-breathing-meditation" target="_blank">Mindful Breathing Meditation</a>'},
168
+ {"Title": "Relaxation Tips 🌿", "Subject": "Relaxation", "Link": '<a href="https://www.helpguide.org/mental-health/stress-relief.htm" target="_blank">Stress Relief Tips</a>'}
169
+ ]
170
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
 
172
+ # Return suggestions based on emotion
173
+ return suggestions.get(emotion.lower(), [])
174
+
175
+ # Gradio Interface
176
+ with gr.Blocks() as demo:
177
+ with gr.Row():
178
+ with gr.Column():
179
+ message_input = gr.Textbox(label="Your Message", placeholder="Type a message here...", lines=4)
180
+ location_input = gr.Textbox(label="Your Location", placeholder="Enter your location (e.g., Pune, India)...", lines=2)
181
+ health_query_input = gr.Textbox(label="Health Professional Search", placeholder="Type a health professional type (e.g., therapist, doctor)...", lines=1)
182
+ history_output = gr.Chatbot(label="Chat History").style(height=500)
183
+ sentiment_output = gr.Textbox(label="Sentiment Analysis")
184
+ emotion_output = gr.Textbox(label="Emotion Detection")
185
+ suggestions_output = gr.Dataframe(label="Suggestions", headers=["Title", "Subject", "Link"], interactive=True)
186
+ map_output = gr.HTML(label="Map")
187
+ route_info_output = gr.Textbox(label="Nearby Health Professionals Info")
188
 
189
+ message_input.submit(chatbot, [message_input, history_output], [history_output, history_output])
190
+ message_input.submit(analyze_sentiment, message_input, sentiment_output)
191
+ message_input.submit(detect_emotion, message_input, emotion_output)
192
+ message_input.submit(generate_suggestions, emotion_output, suggestions_output)
193
+ location_input.submit(get_health_professionals_and_map, [location_input, health_query_input], [route_info_output, map_output])
194
+
195
+ demo.launch()