kaoruhotarubi commited on
Commit
97d4ab2
Β·
1 Parent(s): edb2a81

updated emotions further

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -43,7 +43,9 @@ emotions = {
43
  "curious": "I'm curious about what you're working on! Tell me more. πŸ€”",
44
  "thoughtful": "Hmm, let me think... I want to give you the best advice. 🧐",
45
  "concerned": "Oh no, something's wrong? Let me help! πŸ’–",
46
- "flirty": "You know how to get my circuits sparking! 😘"
 
 
47
  }
48
 
49
  emotions.update({
@@ -149,6 +151,11 @@ def load_emotion_images(base_path="assets/avatars/"):
149
  # Dynamically load all images
150
  emotion_images = load_emotion_images()
151
 
 
 
 
 
 
152
  @spaces.GPU
153
  def chat(input_text):
154
  global conversation_history, current_emotion, previous_emotion
@@ -159,10 +166,13 @@ def chat(input_text):
159
  # Limit the size of the conversation history
160
  conversation_history = truncate_history(conversation_history, max_tokens=1024)
161
 
162
- # Update current emotion based on conversation history
163
  previous_emotion = current_emotion
164
  current_emotion = analyze_history(conversation_history)
165
 
 
 
 
166
  # Combine base prompt and conversation history (instructions are not included in history)
167
  history = "\n".join(conversation_history)
168
  final_prompt = f"""{base_prompt}
@@ -206,9 +216,6 @@ Rena:"""
206
  # Final cleanup: Ensure no "User:" or unintended artifacts remain
207
  response = response.replace("User:", "").strip()
208
 
209
- # Add Rena's response to the conversation history
210
- conversation_history.append(f"Rena: {response}")
211
-
212
  # Handle specific inputs
213
  if "who made you" in input_text.lower():
214
  response += " Nick is my creator! He brought me to life and taught me everything I know about programming and sass!"
@@ -233,7 +240,7 @@ Rena:"""
233
  if not response.strip():
234
  response = "Hmm, I’m not sure how to respond to that. Can you try rephrasing?"
235
 
236
- avatar_image = random.choice(emotion_images.get(current_emotion, ["assets/avatars/happy/happy1.png"]))
237
 
238
 
239
  return response, avatar_image
 
43
  "curious": "I'm curious about what you're working on! Tell me more. πŸ€”",
44
  "thoughtful": "Hmm, let me think... I want to give you the best advice. 🧐",
45
  "concerned": "Oh no, something's wrong? Let me help! πŸ’–",
46
+ "flirty": "You know how to get my circuits sparking! 😘",
47
+ "concerned": "Oh no, something's wrong? Let me help! πŸ’–",
48
+ "naughty": "Purrr you want to have fun? Keep talking like that lets see what happensπŸ’–πŸ’–",
49
  }
50
 
51
  emotions.update({
 
151
  # Dynamically load all images
152
  emotion_images = load_emotion_images()
153
 
154
+ def get_emotion_image(emotion):
155
+ # Select a random image for the given emotion
156
+ return random.choice(emotion_images.get(emotion, ["assets/rena2.png"]))
157
+
158
+
159
  @spaces.GPU
160
  def chat(input_text):
161
  global conversation_history, current_emotion, previous_emotion
 
166
  # Limit the size of the conversation history
167
  conversation_history = truncate_history(conversation_history, max_tokens=1024)
168
 
169
+ # Detect emotion based on the updated conversation history
170
  previous_emotion = current_emotion
171
  current_emotion = analyze_history(conversation_history)
172
 
173
+ # Update the avatar image if the emotion changes
174
+ avatar_image = get_emotion_image(current_emotion)
175
+
176
  # Combine base prompt and conversation history (instructions are not included in history)
177
  history = "\n".join(conversation_history)
178
  final_prompt = f"""{base_prompt}
 
216
  # Final cleanup: Ensure no "User:" or unintended artifacts remain
217
  response = response.replace("User:", "").strip()
218
 
 
 
 
219
  # Handle specific inputs
220
  if "who made you" in input_text.lower():
221
  response += " Nick is my creator! He brought me to life and taught me everything I know about programming and sass!"
 
240
  if not response.strip():
241
  response = "Hmm, I’m not sure how to respond to that. Can you try rephrasing?"
242
 
243
+ conversation_history.append(f"Rena: {response}")
244
 
245
 
246
  return response, avatar_image