hashirehtisham commited on
Commit
778d091
1 Parent(s): b563fe0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -105
app.py CHANGED
@@ -144,47 +144,6 @@ Know how your message sounds and how to improve the tone of the message with Emo
144
  <div style='color: green;'>Developed by Hashir Ehtisham</div>
145
  """
146
 
147
- # Forum data
148
- posts = []
149
- comments = {}
150
- users = []
151
-
152
- def register_user(username):
153
- if username not in users:
154
- users.append(username)
155
- return f"User '{username}' registered successfully."
156
- return f"User '{username}' already registered."
157
-
158
- def submit_post(username, content, is_anonymous):
159
- post_id = len(posts) + 1
160
- posts.append({
161
- 'id': post_id,
162
- 'username': username,
163
- 'content': content,
164
- 'is_anonymous': is_anonymous
165
- })
166
- comments[post_id] = []
167
- return "Post submitted successfully."
168
-
169
- def get_posts():
170
- return pd.DataFrame(posts)
171
-
172
- def submit_comment(post_id, username, comment):
173
- if post_id in comments:
174
- comments[post_id].append({'username': username, 'comment': comment})
175
- return "Comment added successfully."
176
- return "Post not found."
177
-
178
- def get_comments(post_id):
179
- return pd.DataFrame(comments.get(post_id, []))
180
-
181
- def view_user_posts(username):
182
- user_posts = [post for post in posts if post['username'] == username]
183
- return pd.DataFrame(user_posts)
184
-
185
- def view_post_comments(post_id):
186
- return pd.DataFrame(comments.get(post_id, []))
187
-
188
  # Define the Gradio Blocks interface
189
  with gr.Blocks(css=css) as demo:
190
  with gr.Tab("Emotional Support Chatbot"):
@@ -219,79 +178,57 @@ with gr.Blocks(css=css) as demo:
219
  gr.Markdown("# Motivational Quotes")
220
  gr.Markdown(motivational_tagline)
221
 
222
- # Define a dummy response function for motivational quotes
223
- def motivational_response(message):
224
- return "Here’s a motivational quote for you!"
225
-
226
- motivational_message = gr.Textbox(label="Your message")
227
- motivational_output = gr.Textbox(label="Motivational Quote", interactive=False)
228
- motivational_button = gr.Button("Get Quote")
 
 
229
 
230
- motivational_button.click(motivational_response, motivational_message, motivational_output)
 
 
 
 
 
 
 
 
 
231
 
 
 
 
232
  with gr.Tab("Emotions Detector"):
233
  gr.Markdown("# Emotions Detector")
234
  gr.Markdown(emotions_detector_tagline)
235
 
236
- # Define a dummy function for emotions detection
237
- def emotions_detector(message):
238
- return "Your message sounds positive!"
239
-
240
- emotions_message = gr.Textbox(label="Your message")
241
- emotions_output = gr.Textbox(label="Emotions Analysis", interactive=False)
242
- emotions_button = gr.Button("Analyze")
243
-
244
- emotions_button.click(emotions_detector, emotions_message, emotions_output)
245
-
246
- with gr.Tab("Forum"):
247
- gr.Markdown("# Community Support Forum")
248
- gr.Markdown("Connect with others, share your stories, and seek advice.")
249
-
250
- with gr.Row():
251
- username_input = gr.Textbox(label="Username")
252
- register_button = gr.Button("Register")
253
 
254
- with gr.Row():
255
- post_content = gr.Textbox(label="Post Content")
256
- is_anonymous = gr.Checkbox(label="Post Anonymously")
257
- submit_post_button = gr.Button("Submit Post")
258
-
259
- with gr.Row():
260
- view_posts_button = gr.Button("View All Posts")
261
- view_user_posts_button = gr.Button("View User Posts")
262
-
263
- with gr.Row():
264
- post_id_input = gr.Textbox(label="Post ID")
265
- comment_content = gr.Textbox(label="Comment Content")
266
- submit_comment_button = gr.Button("Submit Comment")
267
-
268
- with gr.Row():
269
- view_comments_button = gr.Button("View Post Comments")
270
-
271
- def register_user_wrapper(username):
272
- return register_user(username)
273
-
274
- def submit_post_wrapper(username, content, is_anonymous):
275
- return submit_post(username, content, is_anonymous)
276
-
277
- def get_all_posts():
278
- return get_posts()
279
-
280
- def get_user_posts(username):
281
- return view_user_posts(username)
282
-
283
- def submit_comment_wrapper(post_id, username, comment):
284
- return submit_comment(post_id, username, comment)
285
 
286
- def get_post_comments(post_id):
287
- return view_post_comments(post_id)
 
 
 
 
 
 
 
 
288
 
289
- register_button.click(register_user_wrapper, username_input, "Registration Status")
290
- submit_post_button.click(submit_post_wrapper, [username_input, post_content, is_anonymous], "Post Status")
291
- view_posts_button.click(get_all_posts, None, "All Posts")
292
- view_user_posts_button.click(get_user_posts, username_input, "User Posts")
293
- submit_comment_button.click(submit_comment_wrapper, [post_id_input, username_input, comment_content], "Comment Status")
294
- view_comments_button.click(get_post_comments, post_id_input, "Post Comments")
295
 
296
  if __name__ == "__main__":
297
  demo.launch()
 
144
  <div style='color: green;'>Developed by Hashir Ehtisham</div>
145
  """
146
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  # Define the Gradio Blocks interface
148
  with gr.Blocks(css=css) as demo:
149
  with gr.Tab("Emotional Support Chatbot"):
 
178
  gr.Markdown("# Motivational Quotes")
179
  gr.Markdown(motivational_tagline)
180
 
181
+ system_message_motivational = gr.Textbox(value="You are a friendly Motivational Quotes Chatbot.", visible=False)
182
+ chatbot_motivational = gr.Chatbot()
183
+ msg_motivational = gr.Textbox(label="Your message")
184
+ clear_motivational = gr.Button("Clear")
185
+
186
+ with gr.Accordion("Additional Inputs", open=False):
187
+ max_tokens_motivational = gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens")
188
+ temperature_motivational = gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature")
189
+ top_p_motivational = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)")
190
 
191
+ def respond_wrapper_motivational(message, chat_history, system_message_val, max_tokens_val, temperature_val, top_p_val):
192
+ chat_history, _ = send_message(
193
+ message=message,
194
+ history=chat_history,
195
+ system_message=system_message_val,
196
+ max_tokens=max_tokens_val,
197
+ temperature=temperature_val,
198
+ top_p=top_p_val,
199
+ )
200
+ return gr.update(value=""), chat_history
201
 
202
+ msg_motivational.submit(respond_wrapper_motivational, [msg_motivational, chatbot_motivational, system_message_motivational, max_tokens_motivational, temperature_motivational, top_p_motivational], [msg_motivational, chatbot_motivational])
203
+ clear_motivational.click(lambda: None, None, chatbot_motivational, queue=False)
204
+
205
  with gr.Tab("Emotions Detector"):
206
  gr.Markdown("# Emotions Detector")
207
  gr.Markdown(emotions_detector_tagline)
208
 
209
+ system_message_emotions = gr.Textbox(value="You are an Emotions Detector Chatbot. Analyze the tone of the message (happy, sad, funny, excited, regret, depressed, joy, surprise, fear, anger) and provide suggestions to improve the message.", visible=False)
210
+ chatbot_emotions = gr.Chatbot()
211
+ msg_emotions = gr.Textbox(label="Your message")
212
+ clear_emotions = gr.Button("Clear")
 
 
 
 
 
 
 
 
 
 
 
 
 
213
 
214
+ with gr.Accordion("Additional Inputs", open=False):
215
+ max_tokens_emotions = gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens")
216
+ temperature_emotions = gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature")
217
+ top_p_emotions = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
 
219
+ def respond_wrapper_emotions(message, chat_history, system_message_val, max_tokens_val, temperature_val, top_p_val):
220
+ chat_history, _ = send_message(
221
+ message=message,
222
+ history=chat_history,
223
+ system_message=system_message_val,
224
+ max_tokens=max_tokens_val,
225
+ temperature=temperature_val,
226
+ top_p=top_p_val,
227
+ )
228
+ return gr.update(value=""), chat_history
229
 
230
+ msg_emotions.submit(respond_wrapper_emotions, [msg_emotions, chatbot_emotions, system_message_emotions, max_tokens_emotions, temperature_emotions, top_p_emotions], [msg_emotions, chatbot_emotions])
231
+ clear_emotions.click(lambda: None, None, chatbot_emotions, queue=False)
 
 
 
 
232
 
233
  if __name__ == "__main__":
234
  demo.launch()