Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -161,65 +161,90 @@ def generate_suggestions(emotion):
|
|
161 |
|
162 |
return suggestions.get(emotion, [])
|
163 |
|
164 |
-
#
|
165 |
-
|
166 |
-
|
167 |
-
# Chatbot interaction
|
168 |
-
history, _ = chatbot(message, history)
|
169 |
-
|
170 |
-
# Sentiment analysis
|
171 |
-
sentiment_response = analyze_sentiment(message)
|
172 |
-
|
173 |
-
# Emotion detection
|
174 |
-
emotion_response = detect_emotion(message)
|
175 |
-
|
176 |
-
# Health professional search and map display
|
177 |
-
route_info, map_html = get_health_professionals_and_map(location, health_query)
|
178 |
-
|
179 |
-
# Generate suggestions based on the detected emotion
|
180 |
-
suggestions = generate_suggestions(emotion_response.split(': ')[1])
|
181 |
-
|
182 |
-
# Create a DataFrame for displaying suggestions
|
183 |
-
suggestions_df = pd.DataFrame(suggestions)
|
184 |
-
|
185 |
-
return history, sentiment_response, emotion_response, route_info, map_html, gr.DataFrame(suggestions_df, headers=["Title", "Subject", "Link"]), state
|
186 |
-
else:
|
187 |
-
return history, "", "", "", "", gr.DataFrame([], headers=["Title", "Subject", "Link"]), state
|
188 |
-
|
189 |
-
# Gradio UI components
|
190 |
-
message_input = gr.Textbox(lines=1, label="π¬ Message")
|
191 |
-
location_input = gr.Textbox(value="Honolulu, HI", label="π Current Location")
|
192 |
-
health_query_input = gr.Textbox(value="doctor", label="π©Ί Health Professional Query (e.g., doctor, psychiatrist, psychologist)")
|
193 |
-
submit_button = gr.Button("π Submit")
|
194 |
-
|
195 |
-
# Updated chat history component with 'messages' type
|
196 |
-
chat_history = gr.Chatbot(label="Well-Being Chat History", type='messages')
|
197 |
-
|
198 |
-
# Outputs
|
199 |
-
sentiment_output = gr.Textbox(label="π¬ Sentiment Analysis Result")
|
200 |
-
emotion_output = gr.Textbox(label="π Emotion Detection Result")
|
201 |
-
route_info_output = gr.Textbox(label="π©Ί Health Professionals Information")
|
202 |
-
map_output = gr.HTML(label="πΊοΈ Map with Health Professionals")
|
203 |
-
suggestions_output = gr.DataFrame(label="π Well-Being Suggestions", headers=["Title", "Subject", "Link"])
|
204 |
-
|
205 |
-
# Create Gradio interface with custom CSS for gradient background
|
206 |
-
css = """
|
207 |
body {
|
208 |
-
background: linear-gradient(
|
209 |
font-family: Arial, sans-serif;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
}
|
211 |
"""
|
212 |
|
213 |
-
#
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
)
|
223 |
-
|
224 |
-
#
|
225 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|