Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import os
|
| 2 |
-
import gradio as gr
|
| 3 |
import nltk
|
| 4 |
import numpy as np
|
| 5 |
import tflearn
|
|
@@ -12,6 +11,7 @@ from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipe
|
|
| 12 |
import googlemaps
|
| 13 |
import folium
|
| 14 |
import torch
|
|
|
|
| 15 |
|
| 16 |
# Suppress TensorFlow warnings
|
| 17 |
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
|
@@ -155,7 +155,7 @@ def get_health_professionals_and_map(location, query):
|
|
| 155 |
# Use a list of values to append each professional
|
| 156 |
professionals.append([place['name'], place.get('vicinity', 'No address provided')])
|
| 157 |
folium.Marker(
|
| 158 |
-
location=[place["geometry"]["location"]["lat"], place["geometry"]["location"]["lng"]],
|
| 159 |
popup=f"{place['name']}"
|
| 160 |
).add_to(map_)
|
| 161 |
return professionals, map_._repr_html_()
|
|
@@ -164,123 +164,46 @@ def get_health_professionals_and_map(location, query):
|
|
| 164 |
except Exception as e:
|
| 165 |
return [], "" # Return empty list on exception
|
| 166 |
|
| 167 |
-
#
|
| 168 |
-
|
| 169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
sentiment_result = analyze_sentiment(user_input)
|
| 171 |
emotion_result, cleaned_emotion = detect_emotion(user_input)
|
| 172 |
suggestions = generate_suggestions(cleaned_emotion)
|
| 173 |
professionals, map_html = get_health_professionals_and_map(location, query)
|
| 174 |
-
return chatbot_history, sentiment_result, emotion_result, suggestions, professionals, map_html
|
| 175 |
-
|
| 176 |
-
# CSS Styling
|
| 177 |
-
custom_css = """
|
| 178 |
-
body {
|
| 179 |
-
font-family: 'Roboto', sans-serif;
|
| 180 |
-
background-color: #3c6487; /* Set the background color */
|
| 181 |
-
color: white;
|
| 182 |
-
}
|
| 183 |
-
|
| 184 |
-
h1 {
|
| 185 |
-
background: #ffffff;
|
| 186 |
-
color: #000000;
|
| 187 |
-
border-radius: 8px;
|
| 188 |
-
padding: 10px;
|
| 189 |
-
font-weight: bold;
|
| 190 |
-
text-align: center;
|
| 191 |
-
font-size: 2.5rem;
|
| 192 |
-
}
|
| 193 |
-
|
| 194 |
-
textarea, input {
|
| 195 |
-
background: transparent;
|
| 196 |
-
color: black;
|
| 197 |
-
border: 2px solid orange;
|
| 198 |
-
padding: 8px;
|
| 199 |
-
font-size: 1rem;
|
| 200 |
-
caret-color: black;
|
| 201 |
-
outline: none;
|
| 202 |
-
border-radius: 8px;
|
| 203 |
-
}
|
| 204 |
-
|
| 205 |
-
textarea:focus, input:focus {
|
| 206 |
-
background: transparent;
|
| 207 |
-
color: black;
|
| 208 |
-
border: 2px solid orange;
|
| 209 |
-
outline: none;
|
| 210 |
-
}
|
| 211 |
-
|
| 212 |
-
textarea:hover, input:hover {
|
| 213 |
-
background: transparent;
|
| 214 |
-
color: black;
|
| 215 |
-
border: 2px solid orange;
|
| 216 |
-
}
|
| 217 |
-
|
| 218 |
-
.df-container {
|
| 219 |
-
background: white;
|
| 220 |
-
color: black;
|
| 221 |
-
border: 2px solid orange;
|
| 222 |
-
border-radius: 10px;
|
| 223 |
-
padding: 10px;
|
| 224 |
-
font-size: 14px;
|
| 225 |
-
max-height: 400px;
|
| 226 |
-
height: auto;
|
| 227 |
-
overflow-y: auto;
|
| 228 |
-
}
|
| 229 |
-
|
| 230 |
-
#suggestions-title {
|
| 231 |
-
text-align: center !important; /* Ensure the centering is applied */
|
| 232 |
-
font-weight: bold !important; /* Ensure bold is applied */
|
| 233 |
-
color: white !important; /* Ensure color is applied */
|
| 234 |
-
font-size: 4.2rem !important; /* Ensure font size is applied */
|
| 235 |
-
margin-bottom: 20px !important; /* Ensure margin is applied */
|
| 236 |
-
}
|
| 237 |
-
|
| 238 |
-
/* Style for the submit button */
|
| 239 |
-
.gr-button {
|
| 240 |
-
background-color: #ae1c93; /* Set the background color to #ae1c93 */
|
| 241 |
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06);
|
| 242 |
-
transition: background-color 0.3s ease;
|
| 243 |
-
}
|
| 244 |
-
|
| 245 |
-
.gr-button:hover {
|
| 246 |
-
background-color: #8f167b;
|
| 247 |
-
}
|
| 248 |
-
|
| 249 |
-
.gr-button:active {
|
| 250 |
-
background-color: #7f156b;
|
| 251 |
-
}
|
| 252 |
-
"""
|
| 253 |
-
# Gradio Application
|
| 254 |
-
|
| 255 |
-
with gr.Blocks(css=custom_css) as app:
|
| 256 |
-
gr.HTML("<h1>🌟 Well-Being Companion</h1>")
|
| 257 |
-
with gr.Row():
|
| 258 |
-
user_input = gr.Textbox(label="Please Enter Your Message Here")
|
| 259 |
-
location = gr.Textbox(label="Please Enter Your Current Location Here")
|
| 260 |
-
query = gr.Textbox(label="Please Enter Which Health Professional You Want To Search Nearby")
|
| 261 |
-
|
| 262 |
-
# Predict Disease Button
|
| 263 |
-
predict_disease = gr.Button(value="Predict Disease", variant="secondary")
|
| 264 |
-
predict_disease.click(lambda: None, [], _js=f"() => window.open('https://huggingface.co/spaces/Mishal23/wellBeing', '_blank')")
|
| 265 |
|
| 266 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
|
| 272 |
-
#
|
| 273 |
-
|
|
|
|
| 274 |
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
|
|
|
| 278 |
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
outputs=[chatbot, sentiment, emotion, suggestions, professionals, map_html],
|
| 283 |
-
)
|
| 284 |
|
| 285 |
-
|
|
|
|
|
|
|
| 286 |
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
import nltk
|
| 3 |
import numpy as np
|
| 4 |
import tflearn
|
|
|
|
| 11 |
import googlemaps
|
| 12 |
import folium
|
| 13 |
import torch
|
| 14 |
+
import streamlit as st
|
| 15 |
|
| 16 |
# Suppress TensorFlow warnings
|
| 17 |
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
|
|
|
| 155 |
# Use a list of values to append each professional
|
| 156 |
professionals.append([place['name'], place.get('vicinity', 'No address provided')])
|
| 157 |
folium.Marker(
|
| 158 |
+
location=[place["geometry"]["location"]["lat"], place["geometry"]["location"]["lng"]],
|
| 159 |
popup=f"{place['name']}"
|
| 160 |
).add_to(map_)
|
| 161 |
return professionals, map_._repr_html_()
|
|
|
|
| 164 |
except Exception as e:
|
| 165 |
return [], "" # Return empty list on exception
|
| 166 |
|
| 167 |
+
# Streamlit App Layout
|
| 168 |
+
st.title("🌟 Well-Being Companion")
|
| 169 |
+
|
| 170 |
+
# Input fields
|
| 171 |
+
user_input = st.text_input("Please Enter Your Message Here")
|
| 172 |
+
location = st.text_input("Please Enter Your Current Location Here")
|
| 173 |
+
query = st.text_input("Please Enter Which Health Professional You Want To Search Nearby")
|
| 174 |
+
|
| 175 |
+
# Button to submit
|
| 176 |
+
if st.button("Submit"):
|
| 177 |
+
chatbot_history, _ = generate_chatbot_response(user_input, [])
|
| 178 |
sentiment_result = analyze_sentiment(user_input)
|
| 179 |
emotion_result, cleaned_emotion = detect_emotion(user_input)
|
| 180 |
suggestions = generate_suggestions(cleaned_emotion)
|
| 181 |
professionals, map_html = get_health_professionals_and_map(location, query)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
+
# Display chatbot conversation history
|
| 184 |
+
st.subheader("Chat History")
|
| 185 |
+
for message, response in chatbot_history:
|
| 186 |
+
st.write(f"**You:** {message}")
|
| 187 |
+
st.write(f"**Bot:** {response}")
|
| 188 |
|
| 189 |
+
# Display sentiment
|
| 190 |
+
st.subheader("Detected Sentiment")
|
| 191 |
+
st.write(sentiment_result)
|
| 192 |
|
| 193 |
+
# Display emotion
|
| 194 |
+
st.subheader("Detected Emotion")
|
| 195 |
+
st.write(emotion_result)
|
| 196 |
|
| 197 |
+
# Display suggestions
|
| 198 |
+
st.subheader("Suggestions")
|
| 199 |
+
for suggestion, link in suggestions:
|
| 200 |
+
st.write(f"[{suggestion}]({link})")
|
| 201 |
|
| 202 |
+
# Display professionals
|
| 203 |
+
st.subheader("Nearby Health Professionals")
|
| 204 |
+
st.write(professionals)
|
|
|
|
|
|
|
| 205 |
|
| 206 |
+
# Display map
|
| 207 |
+
st.subheader("Interactive Map")
|
| 208 |
+
st.components.v1.html(map_html, height=500)
|
| 209 |
|