Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -157,7 +157,7 @@ def get_health_professionals_and_map(location, query):
|
|
| 157 |
except Exception as e:
|
| 158 |
return [f"An error occurred: {e}"], ""
|
| 159 |
|
| 160 |
-
# Main Application
|
| 161 |
def app_function(user_input, location, query, history):
|
| 162 |
chatbot_history, _ = generate_chatbot_response(user_input, history)
|
| 163 |
sentiment_result = analyze_sentiment(user_input)
|
|
@@ -173,84 +173,61 @@ body {
|
|
| 173 |
background: linear-gradient(135deg, #0d0d0d, #ff5722);
|
| 174 |
color: white;
|
| 175 |
}
|
| 176 |
-
|
| 177 |
h1 {
|
| 178 |
-
background: #ffffff;
|
| 179 |
-
color: #000000;
|
| 180 |
-
border-radius: 8px;
|
| 181 |
-
padding: 10px;
|
| 182 |
-
font-weight: bold;
|
| 183 |
text-align: center;
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
textarea, input {
|
| 188 |
-
background: transparent;
|
| 189 |
-
color: black;
|
| 190 |
-
border: 2px solid orange;
|
| 191 |
-
padding: 8px;
|
| 192 |
-
font-size: 1rem;
|
| 193 |
-
caret-color: black;
|
| 194 |
-
outline: none;
|
| 195 |
-
border-radius: 8px;
|
| 196 |
-
}
|
| 197 |
-
|
| 198 |
-
textarea:focus, input:focus {
|
| 199 |
-
background: transparent;
|
| 200 |
-
color: black;
|
| 201 |
-
border: 2px solid orange;
|
| 202 |
-
outline: none;
|
| 203 |
-
}
|
| 204 |
-
|
| 205 |
-
textarea:hover, input:hover {
|
| 206 |
-
background: transparent;
|
| 207 |
-
color: black;
|
| 208 |
-
border: 2px solid orange;
|
| 209 |
}
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
color:
|
| 214 |
-
|
| 215 |
-
border
|
|
|
|
|
|
|
| 216 |
padding: 10px;
|
| 217 |
-
font-size: 14px;
|
| 218 |
-
max-height: 400px;
|
| 219 |
-
overflow-y: auto;
|
| 220 |
}
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
font-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
}
|
| 229 |
"""
|
| 230 |
|
| 231 |
-
# Gradio
|
| 232 |
with gr.Blocks(css=custom_css) as app:
|
| 233 |
-
gr.
|
| 234 |
with gr.Row():
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
query = gr.Textbox(label="Search Query")
|
| 238 |
-
chatbot = gr.Chatbot(label="Chat History")
|
| 239 |
-
sentiment = gr.Textbox(label="Detected Sentiment")
|
| 240 |
-
emotion = gr.Textbox(label="Detected Emotion")
|
| 241 |
|
| 242 |
-
|
| 243 |
-
gr.
|
|
|
|
|
|
|
| 244 |
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
|
|
|
|
|
|
|
|
|
| 251 |
app_function,
|
| 252 |
-
inputs=[user_input,
|
| 253 |
-
outputs=[
|
| 254 |
)
|
| 255 |
|
| 256 |
-
|
|
|
|
|
|
| 157 |
except Exception as e:
|
| 158 |
return [f"An error occurred: {e}"], ""
|
| 159 |
|
| 160 |
+
# Main Application Logic
|
| 161 |
def app_function(user_input, location, query, history):
|
| 162 |
chatbot_history, _ = generate_chatbot_response(user_input, history)
|
| 163 |
sentiment_result = analyze_sentiment(user_input)
|
|
|
|
| 173 |
background: linear-gradient(135deg, #0d0d0d, #ff5722);
|
| 174 |
color: white;
|
| 175 |
}
|
|
|
|
| 176 |
h1 {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
text-align: center;
|
| 178 |
+
color: white;
|
| 179 |
+
font-size: 36px;
|
| 180 |
+
font-weight: bold;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
}
|
| 182 |
+
textarea {
|
| 183 |
+
width: 100%;
|
| 184 |
+
height: 150px;
|
| 185 |
+
background-color: #333333;
|
| 186 |
+
color: white;
|
| 187 |
+
border: 1px solid #ff5722;
|
| 188 |
+
border-radius: 5px;
|
| 189 |
+
font-size: 16px;
|
| 190 |
padding: 10px;
|
|
|
|
|
|
|
|
|
|
| 191 |
}
|
| 192 |
+
button {
|
| 193 |
+
background-color: #ff5722;
|
| 194 |
+
color: white;
|
| 195 |
+
font-size: 16px;
|
| 196 |
+
padding: 10px 20px;
|
| 197 |
+
border-radius: 5px;
|
| 198 |
+
border: none;
|
| 199 |
+
cursor: pointer;
|
| 200 |
+
}
|
| 201 |
+
button:hover {
|
| 202 |
+
background-color: #e64a19;
|
| 203 |
}
|
| 204 |
"""
|
| 205 |
|
| 206 |
+
# Gradio Interface Setup
|
| 207 |
with gr.Blocks(css=custom_css) as app:
|
| 208 |
+
gr.Markdown("# 🌟 Mental Health Chatbot App")
|
| 209 |
with gr.Row():
|
| 210 |
+
chatbot_output = gr.Chatbot(label="Chat History", elem_id="chatbox")
|
| 211 |
+
user_input = gr.Textbox(label="Your Message", placeholder="Type something...", interactive=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
|
| 213 |
+
gr.Markdown("### Sentiment, Emotion, and Suggestions")
|
| 214 |
+
sentiment_output = gr.Textbox(label="Sentiment Analysis")
|
| 215 |
+
emotion_output = gr.Textbox(label="Emotion Detected")
|
| 216 |
+
suggestions_output = gr.DataFrame(headers=["Title", "Link"], label="Suggestions")
|
| 217 |
|
| 218 |
+
gr.Markdown("### Locate Health Professionals (Optional)")
|
| 219 |
+
location_input = gr.Textbox(label="Your Location")
|
| 220 |
+
query_input = gr.Textbox(label="Query (e.g., therapist, clinic)", placeholder="Type something...", interactive=True)
|
| 221 |
+
|
| 222 |
+
professionals_output = gr.DataFrame(headers=["Professional", "Address"], label="Nearby Professionals")
|
| 223 |
+
map_output = gr.HTML(label="Map of Professionals")
|
| 224 |
+
|
| 225 |
+
submit_button = gr.Button(value="Submit", elem_id="submit-btn")
|
| 226 |
+
submit_button.click(
|
| 227 |
app_function,
|
| 228 |
+
inputs=[user_input, location_input, query_input, chatbot_output],
|
| 229 |
+
outputs=[chatbot_output, sentiment_output, emotion_output, suggestions_output, professionals_output, map_output]
|
| 230 |
)
|
| 231 |
|
| 232 |
+
# Run the App
|
| 233 |
+
app.launch(share=True)
|