Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -62,7 +62,7 @@ def bag_of_words(s, words):
|
|
| 62 |
return np.array(bag)
|
| 63 |
|
| 64 |
def chatbot(message, history):
|
| 65 |
-
"""Generate chatbot response and append to history
|
| 66 |
history = history or []
|
| 67 |
try:
|
| 68 |
results = chatbot_model.predict([bag_of_words(message, words)])
|
|
@@ -74,8 +74,6 @@ def chatbot(message, history):
|
|
| 74 |
break
|
| 75 |
except Exception as e:
|
| 76 |
response = f"Error: {str(e)} π₯"
|
| 77 |
-
|
| 78 |
-
# Append the message and response as a tuple
|
| 79 |
history.append((message, response))
|
| 80 |
return history, response
|
| 81 |
|
|
@@ -141,12 +139,14 @@ def app_function(message, location, query, history):
|
|
| 141 |
professionals, map_html = get_health_professionals_and_map(location, query) # Find professionals & map
|
| 142 |
return chatbot_history, sentiment, emotion, suggestions, professionals, map_html
|
| 143 |
|
| 144 |
-
#
|
| 145 |
custom_css = """
|
|
|
|
| 146 |
body {
|
| 147 |
background: linear-gradient(135deg, #000000, #ff5722);
|
| 148 |
color: white;
|
| 149 |
-
font-family: '
|
|
|
|
| 150 |
}
|
| 151 |
button {
|
| 152 |
background-color: #ff5722 !important;
|
|
@@ -161,27 +161,42 @@ button {
|
|
| 161 |
button:hover {
|
| 162 |
background-color: #e64a19 !important;
|
| 163 |
}
|
| 164 |
-
textarea, input[type="text"] {
|
| 165 |
-
background:
|
| 166 |
color: white !important;
|
| 167 |
border: 2px solid #ff5722 !important;
|
| 168 |
padding: 12px !important;
|
| 169 |
border-radius: 8px !important;
|
| 170 |
font-size: 14px;
|
| 171 |
}
|
| 172 |
-
|
| 173 |
-
|
| 174 |
}
|
| 175 |
-
.
|
| 176 |
-
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
}
|
| 179 |
"""
|
| 180 |
|
| 181 |
# Gradio Interface
|
| 182 |
with gr.Blocks(css=custom_css) as app:
|
| 183 |
-
gr.
|
| 184 |
-
gr.
|
| 185 |
|
| 186 |
with gr.Row():
|
| 187 |
user_message = gr.Textbox(label="Your Message", placeholder="Enter your message...")
|
|
@@ -189,7 +204,7 @@ with gr.Blocks(css=custom_css) as app:
|
|
| 189 |
search_query = gr.Textbox(label="Query", placeholder="Search for professionals...")
|
| 190 |
submit_btn = gr.Button("Submit")
|
| 191 |
|
| 192 |
-
chatbot_box = gr.Chatbot(label="Chat History") #
|
| 193 |
emotion_output = gr.Textbox(label="Detected Emotion")
|
| 194 |
sentiment_output = gr.Textbox(label="Detected Sentiment")
|
| 195 |
suggestions_output = gr.DataFrame(headers=["Title", "Links"], label="Suggestions")
|
|
|
|
| 62 |
return np.array(bag)
|
| 63 |
|
| 64 |
def chatbot(message, history):
|
| 65 |
+
"""Generate chatbot response and append to history."""
|
| 66 |
history = history or []
|
| 67 |
try:
|
| 68 |
results = chatbot_model.predict([bag_of_words(message, words)])
|
|
|
|
| 74 |
break
|
| 75 |
except Exception as e:
|
| 76 |
response = f"Error: {str(e)} π₯"
|
|
|
|
|
|
|
| 77 |
history.append((message, response))
|
| 78 |
return history, response
|
| 79 |
|
|
|
|
| 139 |
professionals, map_html = get_health_professionals_and_map(location, query) # Find professionals & map
|
| 140 |
return chatbot_history, sentiment, emotion, suggestions, professionals, map_html
|
| 141 |
|
| 142 |
+
# Enhanced CSS for Black-Themed Interface
|
| 143 |
custom_css = """
|
| 144 |
+
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');
|
| 145 |
body {
|
| 146 |
background: linear-gradient(135deg, #000000, #ff5722);
|
| 147 |
color: white;
|
| 148 |
+
font-family: 'Roboto', sans-serif;
|
| 149 |
+
text-align: center;
|
| 150 |
}
|
| 151 |
button {
|
| 152 |
background-color: #ff5722 !important;
|
|
|
|
| 161 |
button:hover {
|
| 162 |
background-color: #e64a19 !important;
|
| 163 |
}
|
| 164 |
+
textarea, input[type="text"], .gr-chatbot {
|
| 165 |
+
background: #000000 !important;
|
| 166 |
color: white !important;
|
| 167 |
border: 2px solid #ff5722 !important;
|
| 168 |
padding: 12px !important;
|
| 169 |
border-radius: 8px !important;
|
| 170 |
font-size: 14px;
|
| 171 |
}
|
| 172 |
+
.gr-textbox {
|
| 173 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.5);
|
| 174 |
}
|
| 175 |
+
.output-container, .gr-html, .gr-textbox, .gr-dataframe {
|
| 176 |
+
background: #000000 !important;
|
| 177 |
+
color: white !important;
|
| 178 |
+
border: 2px solid #ff5722 !important;
|
| 179 |
+
border-radius: 8px !important;
|
| 180 |
+
padding: 10px;
|
| 181 |
+
}
|
| 182 |
+
h1 {
|
| 183 |
+
font-size: 3rem;
|
| 184 |
+
font-weight: bold;
|
| 185 |
+
margin-bottom: 10px;
|
| 186 |
+
text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.6);
|
| 187 |
+
}
|
| 188 |
+
h2 {
|
| 189 |
+
font-weight: 400;
|
| 190 |
+
font-size: 1.8rem;
|
| 191 |
+
color: white;
|
| 192 |
+
text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.4);
|
| 193 |
}
|
| 194 |
"""
|
| 195 |
|
| 196 |
# Gradio Interface
|
| 197 |
with gr.Blocks(css=custom_css) as app:
|
| 198 |
+
gr.HTML("<h1>π Well-Being Companion</h1>")
|
| 199 |
+
gr.HTML("<h2>Empowering Your Well-Being Journey π</h2>")
|
| 200 |
|
| 201 |
with gr.Row():
|
| 202 |
user_message = gr.Textbox(label="Your Message", placeholder="Enter your message...")
|
|
|
|
| 204 |
search_query = gr.Textbox(label="Query", placeholder="Search for professionals...")
|
| 205 |
submit_btn = gr.Button("Submit")
|
| 206 |
|
| 207 |
+
chatbot_box = gr.Chatbot(label="Chat History") # Chatbot history (black background)
|
| 208 |
emotion_output = gr.Textbox(label="Detected Emotion")
|
| 209 |
sentiment_output = gr.Textbox(label="Detected Sentiment")
|
| 210 |
suggestions_output = gr.DataFrame(headers=["Title", "Links"], label="Suggestions")
|