hashirehtisham commited on
Commit
097f6ad
·
verified ·
1 Parent(s): d498636

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -19
app.py CHANGED
@@ -2,18 +2,6 @@ import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  from transformers import pipeline
4
 
5
- # Initialize the emotion classifier
6
- classifier = pipeline("text-classification", model='bhadresh-savani/distilbert-base-uncased-emotion', return_all_scores=True)
7
-
8
- # Define the function for emotion detection
9
- def detect_emotions(emotion_input):
10
- prediction = classifier(emotion_input)
11
- output = {emotion["label"]: emotion["score"] for emotion in prediction[0]}
12
- return output
13
-
14
- # Examples for the emotion detector
15
- examples = [["I am happy that I gifted my son a robot"], ["Sorry for being late"]]
16
-
17
  # CSS to hide footer and customize button
18
  css = """
19
  footer {display:none !important}
@@ -144,6 +132,18 @@ Hello! I'm here to support you emotionally and answer any questions. How are you
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"):
@@ -174,14 +174,61 @@ with gr.Blocks(css=css) as demo:
174
  msg.submit(respond_wrapper, [msg, chatbot, system_message, max_tokens, temperature, top_p], [msg, chatbot])
175
  clear.click(lambda: None, None, chatbot, queue=False)
176
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
  with gr.Tab("Emotions Detector"):
178
- gr.Interface(
179
- fn=detect_emotions,
180
- inputs=gr.Textbox(placeholder="Enter text here", label="Input"),
181
- outputs=gr.Label(label="Emotion"),
182
- title="Emotion Detector ",
183
- examples=examples
184
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
 
186
  if __name__ == "__main__":
187
  demo.launch()
 
2
  from huggingface_hub import InferenceClient
3
  from transformers import pipeline
4
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  # CSS to hide footer and customize button
6
  css = """
7
  footer {display:none !important}
 
132
  <div style='color: green;'>Developed by Hashir Ehtisham</div>
133
  """
134
 
135
+ # Motivational tagline for the new tab
136
+ motivational_tagline = """
137
+ Welcome to the Motivational Quotes tab! Let’s ignite your day with some inspiration. What do you need motivation for today?
138
+ <div style='color: green;'>Developed by Hashir Ehtisham</div>
139
+ """
140
+
141
+ # Emotions Detector tagline for the new tab
142
+ emotions_detector_tagline = """
143
+ Know how your message sounds and how to improve the tone of the message with Emotions Detector.
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"):
 
174
  msg.submit(respond_wrapper, [msg, chatbot, system_message, max_tokens, temperature, top_p], [msg, chatbot])
175
  clear.click(lambda: None, None, chatbot, queue=False)
176
 
177
+ with gr.Tab("Motivational Quotes"):
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()