rithvick commited on
Commit
4cf2b31
·
verified ·
1 Parent(s): 6b4f4b4

emotions fix

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -31,7 +31,7 @@ apikey = os.environ["GEMINI_API_KEY"] # Replace or use os.getenv if secret
31
 
32
  # Configure Gemini API for drafting (free)
33
  genai_ext.configure(api_key=apikey)
34
- llm_model = genai_ext.GenerativeModel('gemini-1.5-flash')
35
 
36
  # Real classifiers
37
  emotion_classifier = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base") # For D
@@ -105,7 +105,7 @@ class HumanLikeChatbot:
105
  user_emotion = emotion_result['label']
106
 
107
  # Update bot's mood and irritation
108
- if user_emotion in ['anger', 'disgust'] or any(word in clean_message for word in ['bakwaas', 'stupid', 'idiot']):
109
  self.irritation_level += 0.2 # Build irritation
110
  if self.irritation_level > 0.5:
111
  self.bot_mood = "irritated"
@@ -115,15 +115,16 @@ class HumanLikeChatbot:
115
  elif user_emotion in ['sadness', 'disappointment']:
116
  self.bot_mood = "emotional"
117
  I = 0.7
118
- self.irritation_level = max(0, self.irritation_level - 0.1) # Reduce irritation
119
  elif user_emotion == 'joy':
120
  self.bot_mood = "happy"
121
  I = 0.9
122
- self.irritation_level = 0 # Reset irritation
123
  else:
124
  self.bot_mood = "neutral"
125
  I = 0.5
126
- self.irritation_level = max(0, self.irritation_level - 0.1)
 
127
 
128
  # Draft response from LLM based on bot's mood
129
  prompt = f"""User said: "{clean_message}" | User Mood: {user_emotion} | Bot Mood: {self.bot_mood} | History: {self.history[-2:]} → Reply as a English chatbot , based on this {self.bot_mood}, human-like, no tips or instructions JUST LIKE YOU ARE A HUMAN WITH FEELINGS AND SENSES:"""
@@ -162,7 +163,7 @@ class HumanLikeChatbot:
162
  self.history.append(clean_message)
163
  return full_resp + f" (E Score: {score:.2f})"
164
  except Exception as e:
165
- return f"Error aaya bhai: {str(e)}. Endpoint ya auth check kar."
166
 
167
  # Gradio app
168
  def chat(message, history):
@@ -177,7 +178,7 @@ bot = HumanLikeChatbot()
177
  with gr.Blocks(title="HumanLike Chatbot") as demo:
178
  gr.Markdown("<h1 style='text-align: center;'>HumanLike Chatbot with Emotions and E Score</h1>")
179
  chatbot = gr.Chatbot(height=400)
180
- msg = gr.Textbox(label="Tu:", placeholder="Type your message here...")
181
  clear = gr.Button("Clear")
182
 
183
  msg.submit(chat, [msg, chatbot], [msg, chatbot])
 
31
 
32
  # Configure Gemini API for drafting (free)
33
  genai_ext.configure(api_key=apikey)
34
+ llm_model = genai_ext.GenerativeModel('gemini-1.5-pro')
35
 
36
  # Real classifiers
37
  emotion_classifier = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base") # For D
 
105
  user_emotion = emotion_result['label']
106
 
107
  # Update bot's mood and irritation
108
+ if user_emotion in ['anger', 'disgust'] or any(word in clean_message for word in [ 'stupid', 'idiot']):
109
  self.irritation_level += 0.2 # Build irritation
110
  if self.irritation_level > 0.5:
111
  self.bot_mood = "irritated"
 
115
  elif user_emotion in ['sadness', 'disappointment']:
116
  self.bot_mood = "emotional"
117
  I = 0.7
118
+ self.irritation_level = max(0, self.irritation_level - 0.05 if user_emotion == 'sadness' else self.irritation_level - 0.1) # Slow decrease for sadness, medium for disappointment
119
  elif user_emotion == 'joy':
120
  self.bot_mood = "happy"
121
  I = 0.9
122
+ self.irritation_level = max(0, self.irritation_level - 0.3) # Larger decrease for joy, but not instant reset
123
  else:
124
  self.bot_mood = "neutral"
125
  I = 0.5
126
+ self.irritation_level = max(0, self.irritation_level - 0.05) # Slow decrease in neutral
127
+
128
 
129
  # Draft response from LLM based on bot's mood
130
  prompt = f"""User said: "{clean_message}" | User Mood: {user_emotion} | Bot Mood: {self.bot_mood} | History: {self.history[-2:]} → Reply as a English chatbot , based on this {self.bot_mood}, human-like, no tips or instructions JUST LIKE YOU ARE A HUMAN WITH FEELINGS AND SENSES:"""
 
163
  self.history.append(clean_message)
164
  return full_resp + f" (E Score: {score:.2f})"
165
  except Exception as e:
166
+ return f"Error : {str(e)}."
167
 
168
  # Gradio app
169
  def chat(message, history):
 
178
  with gr.Blocks(title="HumanLike Chatbot") as demo:
179
  gr.Markdown("<h1 style='text-align: center;'>HumanLike Chatbot with Emotions and E Score</h1>")
180
  chatbot = gr.Chatbot(height=400)
181
+ msg = gr.Textbox(label="You:", placeholder="Type your message here...")
182
  clear = gr.Button("Clear")
183
 
184
  msg.submit(chat, [msg, chatbot], [msg, chatbot])