Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,7 +35,7 @@ def classify_message(user_message, bot_response):
|
|
| 35 |
elif "career" in user_message.lower():
|
| 36 |
saved_chats["Career Advice"].append((user_message, bot_response))
|
| 37 |
return "Career Advice"
|
| 38 |
-
elif "suggestions" in user_message.
|
| 39 |
saved_chats["Suggestions"].append((user_message, bot_response))
|
| 40 |
return "Suggestions"
|
| 41 |
else:
|
|
@@ -49,7 +49,7 @@ def chatbot(user_input, history=[]):
|
|
| 49 |
history.append((f"({topic}) You: {user_input}", f"Motivator Bot: {bot_response}"))
|
| 50 |
return history, saved_chats
|
| 51 |
|
| 52 |
-
#
|
| 53 |
def display_saved_chats():
|
| 54 |
display = ""
|
| 55 |
for category, chats in saved_chats.items():
|
|
@@ -59,6 +59,7 @@ def display_saved_chats():
|
|
| 59 |
display += "</div>"
|
| 60 |
return display.strip()
|
| 61 |
|
|
|
|
| 62 |
chat_interface = gr.Blocks(css="""
|
| 63 |
body {
|
| 64 |
font-family: 'Poppins', sans-serif;
|
|
@@ -83,85 +84,4 @@ header, footer {
|
|
| 83 |
padding: 1rem;
|
| 84 |
border-radius: 15px;
|
| 85 |
margin-bottom: 1rem;
|
| 86 |
-
box-shadow: 0px 4px 15px rgba(0, 0,
|
| 87 |
-
}
|
| 88 |
-
|
| 89 |
-
.chatbot-container {
|
| 90 |
-
display: flex;
|
| 91 |
-
flex-direction: column;
|
| 92 |
-
justify-content: space-between;
|
| 93 |
-
border-radius: 15px;
|
| 94 |
-
background: rgba(255, 255, 255, 0.8);
|
| 95 |
-
padding: 1rem;
|
| 96 |
-
height: 400px;
|
| 97 |
-
overflow-y: auto;
|
| 98 |
-
box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.2);
|
| 99 |
-
}
|
| 100 |
-
|
| 101 |
-
input, button {
|
| 102 |
-
border: none;
|
| 103 |
-
padding: 0.8rem;
|
| 104 |
-
border-radius: 10px;
|
| 105 |
-
margin: 0.5rem 0;
|
| 106 |
-
outline: none;
|
| 107 |
-
}
|
| 108 |
-
|
| 109 |
-
input {
|
| 110 |
-
background: #fff;
|
| 111 |
-
color: #333;
|
| 112 |
-
font-size: 1rem;
|
| 113 |
-
}
|
| 114 |
-
|
| 115 |
-
button {
|
| 116 |
-
background: linear-gradient(90deg, #6a11cb, #2575fc);
|
| 117 |
-
color: white;
|
| 118 |
-
font-weight: bold;
|
| 119 |
-
cursor: pointer;
|
| 120 |
-
transition: transform 0.2s, background 0.2s;
|
| 121 |
-
}
|
| 122 |
-
|
| 123 |
-
button:hover {
|
| 124 |
-
transform: scale(1.05);
|
| 125 |
-
background: linear-gradient(90deg, #2575fc, #6a11cb);
|
| 126 |
-
}
|
| 127 |
-
|
| 128 |
-
.chat-category {
|
| 129 |
-
background: rgba(0, 0, 0, 0.05);
|
| 130 |
-
border: 2px solid #ff7eb3;
|
| 131 |
-
margin: 1rem 0;
|
| 132 |
-
padding: 1rem;
|
| 133 |
-
border-radius: 10px;
|
| 134 |
-
transition: transform 0.2s, box-shadow 0.2s;
|
| 135 |
-
}
|
| 136 |
-
|
| 137 |
-
.chat-category:hover {
|
| 138 |
-
transform: translateY(-3px);
|
| 139 |
-
box-shadow: 0px 4px 15px rgba(255, 127, 179, 0.5);
|
| 140 |
-
}
|
| 141 |
-
""")
|
| 142 |
-
|
| 143 |
-
with chat_interface:
|
| 144 |
-
with gr.Row():
|
| 145 |
-
gr.Markdown("<h1 style='text-align:center;'>🌈 Vibrant Motivational Chatbot</h1>")
|
| 146 |
-
with gr.Row():
|
| 147 |
-
gr.Markdown("**Feeling stressed or unmotivated? Share your thoughts and let me help!**")
|
| 148 |
-
with gr.Row():
|
| 149 |
-
chatbot_output = gr.Chatbot(label="Motivator Bot", interactive=True)
|
| 150 |
-
with gr.Row():
|
| 151 |
-
user_input = gr.Textbox(label="Your Message", placeholder="Type something...")
|
| 152 |
-
send_button = gr.Button("Send")
|
| 153 |
-
with gr.Row():
|
| 154 |
-
saved_chats_display = gr.HTML(label="Saved Chats", value=display_saved_chats())
|
| 155 |
-
refresh_button = gr.Button("Refresh Saved Chats")
|
| 156 |
-
|
| 157 |
-
def handle_interaction(user_input, history):
|
| 158 |
-
if not user_input.strip():
|
| 159 |
-
return history, display_saved_chats()
|
| 160 |
-
updated_history, _ = chatbot(user_input, history)
|
| 161 |
-
return updated_history, display_saved_chats()
|
| 162 |
-
|
| 163 |
-
send_button.click(handle_interaction, inputs=[user_input, chatbot_output], outputs=[chatbot_output, saved_chats_display])
|
| 164 |
-
refresh_button.click(display_saved_chats, inputs=[], outputs=saved_chats_display)
|
| 165 |
-
|
| 166 |
-
if __name__ == "__main__":
|
| 167 |
-
chat_interface.launch()
|
|
|
|
| 35 |
elif "career" in user_message.lower():
|
| 36 |
saved_chats["Career Advice"].append((user_message, bot_response))
|
| 37 |
return "Career Advice"
|
| 38 |
+
elif "suggestions" in user_message.lower():
|
| 39 |
saved_chats["Suggestions"].append((user_message, bot_response))
|
| 40 |
return "Suggestions"
|
| 41 |
else:
|
|
|
|
| 49 |
history.append((f"({topic}) You: {user_input}", f"Motivator Bot: {bot_response}"))
|
| 50 |
return history, saved_chats
|
| 51 |
|
| 52 |
+
# Function to display saved chats
|
| 53 |
def display_saved_chats():
|
| 54 |
display = ""
|
| 55 |
for category, chats in saved_chats.items():
|
|
|
|
| 59 |
display += "</div>"
|
| 60 |
return display.strip()
|
| 61 |
|
| 62 |
+
# Gradio Interface setup
|
| 63 |
chat_interface = gr.Blocks(css="""
|
| 64 |
body {
|
| 65 |
font-family: 'Poppins', sans-serif;
|
|
|
|
| 84 |
padding: 1rem;
|
| 85 |
border-radius: 15px;
|
| 86 |
margin-bottom: 1rem;
|
| 87 |
+
box-shadow: 0px 4px 15px rgba(0, 0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|