arpit13 commited on
Commit
a5314d2
·
verified ·
1 Parent(s): 46bfe87

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -29
app.py CHANGED
@@ -51,15 +51,13 @@ def chatbot(user_input, history=[]):
51
 
52
  # Function to display saved chats
53
  def display_saved_chats():
54
- def format_chats(category):
55
- return "\n".join([f"**You**: {u}\n**Bot**: {b}" for u, b in saved_chats[category]]) or "No messages yet."
56
-
57
- return (
58
- format_chats("Stress Management"),
59
- format_chats("Career Advice"),
60
- format_chats("General"),
61
- format_chats("Suggestions")
62
- )
63
 
64
  # Gradio Interface setup
65
  chat_interface = gr.Blocks(css="""
@@ -88,37 +86,83 @@ header, footer {
88
  margin-bottom: 1rem;
89
  box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.2);
90
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  """)
92
 
93
  with chat_interface:
94
  with gr.Row():
95
  gr.Markdown("<h1 style='text-align:center;'>🌈 Vibrant Motivational Chatbot</h1>")
 
 
 
 
96
  with gr.Row():
97
  user_input = gr.Textbox(label="Your Message", placeholder="Type something...")
98
  send_button = gr.Button("Send")
99
  with gr.Row():
100
- chatbot_output = gr.Chatbot(label="Chat History")
101
-
102
- with gr.Row():
103
- with gr.Column():
104
- stress_display = gr.Textbox(label="Stress Management", interactive=False, lines=10)
105
- with gr.Column():
106
- career_display = gr.Textbox(label="Career Advice", interactive=False, lines=10)
107
- with gr.Column():
108
- general_display = gr.Textbox(label="General", interactive=False, lines=10)
109
- with gr.Column():
110
- suggestions_display = gr.Textbox(label="Suggestions", interactive=False, lines=10)
111
 
112
  def handle_interaction(user_input, history):
113
  if not user_input.strip():
114
- return history, *display_saved_chats()
115
  updated_history, _ = chatbot(user_input, history)
116
- return updated_history, *display_saved_chats()
117
-
118
- send_button.click(
119
- fn=handle_interaction,
120
- inputs=[user_input, chatbot_output],
121
- outputs=[chatbot_output, stress_display, career_display, general_display, suggestions_display]
122
- )
123
 
124
- chat_interface.launch()
 
 
51
 
52
  # Function to display saved chats
53
  def display_saved_chats():
54
+ display = ""
55
+ for category, chats in saved_chats.items():
56
+ display += f"<div class='chat-category'><h3>{category}</h3>"
57
+ for user_message, bot_response in chats:
58
+ display += f"<p><strong>You:</strong> {user_message}<br><strong>Bot:</strong> {bot_response}</p>"
59
+ display += "</div>"
60
+ return display.strip()
 
 
61
 
62
  # Gradio Interface setup
63
  chat_interface = gr.Blocks(css="""
 
86
  margin-bottom: 1rem;
87
  box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.2);
88
  }
89
+
90
+ .chatbot-container {
91
+ display: flex;
92
+ flex-direction: column;
93
+ justify-content: space-between;
94
+ border-radius: 15px;
95
+ background: rgba(255, 255, 255, 0.8);
96
+ padding: 1rem;
97
+ height: 400px;
98
+ overflow-y: auto;
99
+ box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.2);
100
+ }
101
+
102
+ input, button {
103
+ border: none;
104
+ padding: 0.8rem;
105
+ border-radius: 10px;
106
+ margin: 0.5rem 0;
107
+ outline: none;
108
+ }
109
+
110
+ input {
111
+ background: #fff;
112
+ color: #333;
113
+ font-size: 1rem;
114
+ }
115
+
116
+ button {
117
+ background: linear-gradient(90deg, #6a11cb, #2575fc);
118
+ color: white;
119
+ font-weight: bold;
120
+ cursor: pointer;
121
+ transition: transform 0.2s, background 0.2s;
122
+ }
123
+
124
+ button:hover {
125
+ transform: scale(1.05);
126
+ background: linear-gradient(90deg, #2575fc, #6a11cb);
127
+ }
128
+
129
+ .chat-category {
130
+ background: rgba(0, 0, 0, 0.05);
131
+ border: 2px solid #ff7eb3;
132
+ margin: 1rem 0;
133
+ padding: 1rem;
134
+ border-radius: 10px;
135
+ transition: transform 0.2s, box-shadow 0.2s;
136
+ }
137
+
138
+ .chat-category:hover {
139
+ transform: translateY(-3px);
140
+ box-shadow: 0px 4px 15px rgba(255, 127, 179, 0.5);
141
+ }
142
  """)
143
 
144
  with chat_interface:
145
  with gr.Row():
146
  gr.Markdown("<h1 style='text-align:center;'>🌈 Vibrant Motivational Chatbot</h1>")
147
+ with gr.Row():
148
+ gr.Markdown("*Feeling stressed or unmotivated? Share your thoughts and let me help!*")
149
+ with gr.Row():
150
+ chatbot_output = gr.Chatbot(label="Motivator Bot")
151
  with gr.Row():
152
  user_input = gr.Textbox(label="Your Message", placeholder="Type something...")
153
  send_button = gr.Button("Send")
154
  with gr.Row():
155
+ saved_chats_display = gr.HTML(label="Saved Chats", value=display_saved_chats())
156
+ refresh_button = gr.Button("Refresh Saved Chats")
 
 
 
 
 
 
 
 
 
157
 
158
  def handle_interaction(user_input, history):
159
  if not user_input.strip():
160
+ return history, display_saved_chats()
161
  updated_history, _ = chatbot(user_input, history)
162
+ return updated_history, display_saved_chats()
163
+
164
+ send_button.click(handle_interaction, inputs=[user_input, chatbot_output], outputs=[chatbot_output, saved_chats_display])
165
+ refresh_button.click(display_saved_chats, inputs=[], outputs=saved_chats_display)
 
 
 
166
 
167
+ if _name_ == "_main_":
168
+ chat_interface.launch()