Spaces:
Runtime error
Runtime error
Commit ·
e0a83aa
1
Parent(s): fd27953
concerned sterak emotion
Browse files
app.py
CHANGED
|
@@ -180,10 +180,11 @@ def get_emotion_image(emotion):
|
|
| 180 |
def remove_emojis(text):
|
| 181 |
return re.sub(r'[^\w\s,.\'\"!?]', '', text)
|
| 182 |
|
|
|
|
| 183 |
|
| 184 |
@spaces.GPU
|
| 185 |
def chat(input_text):
|
| 186 |
-
global conversation_history, current_emotion, previous_emotion
|
| 187 |
|
| 188 |
# Add user input to the conversation history
|
| 189 |
conversation_history.append(f"User: {input_text}")
|
|
@@ -195,6 +196,15 @@ def chat(input_text):
|
|
| 195 |
previous_emotion = current_emotion
|
| 196 |
current_emotion = analyze_history(conversation_history)
|
| 197 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
# Update the avatar image if the emotion changes
|
| 199 |
avatar_image = get_emotion_image(current_emotion)
|
| 200 |
|
|
@@ -238,16 +248,7 @@ Rena:"""
|
|
| 238 |
if emotional_prefix and not response.startswith(emotional_prefix):
|
| 239 |
response = f"{emotional_prefix} {response}".strip()
|
| 240 |
|
| 241 |
-
|
| 242 |
-
concerned_streak += 1
|
| 243 |
-
else:
|
| 244 |
-
concerned_streak = max(0, concerned_streak - 1)
|
| 245 |
-
|
| 246 |
-
if concerned_streak >= 3:
|
| 247 |
-
current_emotion = random.choice(["happy", "thoughtful", "playful"]) # ✅ Break the loop
|
| 248 |
-
concerned_streak = 0
|
| 249 |
-
|
| 250 |
-
# Final cleanup: Ensure no "User:" or unintended artifacts remain
|
| 251 |
response = response.replace("User:", "").strip()
|
| 252 |
|
| 253 |
# Handle specific inputs
|
|
|
|
| 180 |
def remove_emojis(text):
|
| 181 |
return re.sub(r'[^\w\s,.\'\"!?]', '', text)
|
| 182 |
|
| 183 |
+
concerned_streak = 0
|
| 184 |
|
| 185 |
@spaces.GPU
|
| 186 |
def chat(input_text):
|
| 187 |
+
global conversation_history, current_emotion, previous_emotion, concerned_streak
|
| 188 |
|
| 189 |
# Add user input to the conversation history
|
| 190 |
conversation_history.append(f"User: {input_text}")
|
|
|
|
| 196 |
previous_emotion = current_emotion
|
| 197 |
current_emotion = analyze_history(conversation_history)
|
| 198 |
|
| 199 |
+
if current_emotion == "concerned":
|
| 200 |
+
concerned_streak += 1
|
| 201 |
+
else:
|
| 202 |
+
concerned_streak = max(0, concerned_streak - 1)
|
| 203 |
+
|
| 204 |
+
if concerned_streak >= 3:
|
| 205 |
+
current_emotion = random.choice(["happy", "thoughtful", "playful"])
|
| 206 |
+
concerned_streak = 0
|
| 207 |
+
|
| 208 |
# Update the avatar image if the emotion changes
|
| 209 |
avatar_image = get_emotion_image(current_emotion)
|
| 210 |
|
|
|
|
| 248 |
if emotional_prefix and not response.startswith(emotional_prefix):
|
| 249 |
response = f"{emotional_prefix} {response}".strip()
|
| 250 |
|
| 251 |
+
# Final cleanup: Ensure no "User:" or unintended artifacts remain
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
response = response.replace("User:", "").strip()
|
| 253 |
|
| 254 |
# Handle specific inputs
|