Spaces:
Runtime error
Runtime error
Commit ·
77ae8b5
1
Parent(s): dcfb254
added dynamic avatar changes
Browse files- app.py +30 -11
- assets/emotions/angry2.png +0 -3
- assets/emotions/angry3.png +0 -3
- assets/emotions/angry4.png +0 -3
- assets/emotions/angry5.png +0 -3
- assets/emotions/angy.png +0 -3
- assets/emotions/excited.png +0 -3
- assets/emotions/excited2.png +0 -3
- assets/emotions/flirty.png +0 -3
- assets/emotions/flirty2.png +0 -3
- assets/emotions/flirty3.png +0 -3
- assets/emotions/flirty4.png +0 -3
- assets/emotions/happy.png +0 -3
- assets/emotions/thinking.png +0 -3
- assets/emotions/thinking2.png +0 -3
- assets/emotions/thinking3.png +0 -3
- assets/emotions/upset.png +0 -3
- assets/emotions/upset2.png +0 -3
- assets/emotions/upset3.png +0 -3
- assets/emotions/upset4.png +0 -3
app.py
CHANGED
|
@@ -3,6 +3,7 @@ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
|
| 3 |
import torch
|
| 4 |
import gradio as gr
|
| 5 |
from PIL import Image
|
|
|
|
| 6 |
import random
|
| 7 |
|
| 8 |
# Define the model name
|
|
@@ -58,7 +59,8 @@ emotion_keywords = {
|
|
| 58 |
"curious": ["curious", "wonder", "question", "thinking"],
|
| 59 |
"thoughtful": ["sad", "thoughtful", "hmm", "ponder", "upset"],
|
| 60 |
"concerned": ["error", "wrong", "problem", "issue", "stuck"],
|
| 61 |
-
"mischievous": ["trouble", "mischief", "sneaky", "prank"]
|
|
|
|
| 62 |
}
|
| 63 |
|
| 64 |
current_emotion = "happy"
|
|
@@ -128,6 +130,24 @@ def truncate_history(history, max_tokens=1024):
|
|
| 128 |
return truncated_history
|
| 129 |
previous_emotion = None
|
| 130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
@spaces.GPU
|
| 132 |
def chat(input_text):
|
| 133 |
global conversation_history, current_emotion, previous_emotion
|
|
@@ -211,8 +231,11 @@ Rena:"""
|
|
| 211 |
# Handle fallback if response is empty
|
| 212 |
if not response.strip():
|
| 213 |
response = "Hmm, I’m not sure how to respond to that. Can you try rephrasing?"
|
|
|
|
|
|
|
|
|
|
| 214 |
|
| 215 |
-
return response
|
| 216 |
|
| 217 |
|
| 218 |
|
|
@@ -236,19 +259,15 @@ css = """
|
|
| 236 |
|
| 237 |
# Define the Gradio interface
|
| 238 |
with gr.Blocks(css=css) as interface:
|
| 239 |
-
# Static avatar section
|
| 240 |
with gr.Row():
|
| 241 |
-
gr.Image(value=
|
| 242 |
-
|
| 243 |
-
# Chatbox section
|
| 244 |
with gr.Row():
|
| 245 |
-
user_input = gr.Textbox(label="Your Message", lines=2)
|
| 246 |
rena_response = gr.Textbox(label="Rena's Response", lines=10, interactive=False)
|
|
|
|
|
|
|
|
|
|
| 247 |
|
| 248 |
-
# Submit button
|
| 249 |
-
with gr.Row():
|
| 250 |
-
submit_button = gr.Button("Submit")
|
| 251 |
-
submit_button.click(chat, inputs=[user_input], outputs=[rena_response])
|
| 252 |
|
| 253 |
# Launch the app
|
| 254 |
interface.launch()
|
|
|
|
| 3 |
import torch
|
| 4 |
import gradio as gr
|
| 5 |
from PIL import Image
|
| 6 |
+
import os
|
| 7 |
import random
|
| 8 |
|
| 9 |
# Define the model name
|
|
|
|
| 59 |
"curious": ["curious", "wonder", "question", "thinking"],
|
| 60 |
"thoughtful": ["sad", "thoughtful", "hmm", "ponder", "upset"],
|
| 61 |
"concerned": ["error", "wrong", "problem", "issue", "stuck"],
|
| 62 |
+
"mischievous": ["trouble", "mischief", "sneaky", "prank"],
|
| 63 |
+
"naughty": ["sexy", "naughty", "slut", "bad girl","slutty", "tease" "whore" "cum" "tits" "ass" "shake" "tail" "pussy" ]
|
| 64 |
}
|
| 65 |
|
| 66 |
current_emotion = "happy"
|
|
|
|
| 130 |
return truncated_history
|
| 131 |
previous_emotion = None
|
| 132 |
|
| 133 |
+
def load_emotion_images(base_path="assets/avatars/"):
|
| 134 |
+
emotion_images = {}
|
| 135 |
+
for emotion in os.listdir(base_path):
|
| 136 |
+
emotion_path = os.path.join(base_path, emotion)
|
| 137 |
+
if os.path.isdir(emotion_path):
|
| 138 |
+
# Get all image files in the directory
|
| 139 |
+
images = [
|
| 140 |
+
os.path.join(emotion_path, img)
|
| 141 |
+
for img in os.listdir(emotion_path)
|
| 142 |
+
if img.endswith((".png", ".jpg", ".jpeg")) # Support common image formats
|
| 143 |
+
]
|
| 144 |
+
if images:
|
| 145 |
+
emotion_images[emotion] = images
|
| 146 |
+
return emotion_images
|
| 147 |
+
|
| 148 |
+
# Dynamically load all images
|
| 149 |
+
emotion_images = load_emotion_images()
|
| 150 |
+
|
| 151 |
@spaces.GPU
|
| 152 |
def chat(input_text):
|
| 153 |
global conversation_history, current_emotion, previous_emotion
|
|
|
|
| 231 |
# Handle fallback if response is empty
|
| 232 |
if not response.strip():
|
| 233 |
response = "Hmm, I’m not sure how to respond to that. Can you try rephrasing?"
|
| 234 |
+
|
| 235 |
+
avatar_image = random.choice(emotion_images.get(current_emotion, ["assets/avatars/happy/happy1.png"]))
|
| 236 |
+
|
| 237 |
|
| 238 |
+
return response, avatar_image
|
| 239 |
|
| 240 |
|
| 241 |
|
|
|
|
| 259 |
|
| 260 |
# Define the Gradio interface
|
| 261 |
with gr.Blocks(css=css) as interface:
|
|
|
|
| 262 |
with gr.Row():
|
| 263 |
+
avatar = gr.Image(value="assets/avatars/rena2.png", label="Rena", interactive=False, show_label=False, elem_id="rena_avatar")
|
|
|
|
|
|
|
| 264 |
with gr.Row():
|
| 265 |
+
user_input = gr.Textbox(label="Your Message", lines=2, interactive=True, submit=True)
|
| 266 |
rena_response = gr.Textbox(label="Rena's Response", lines=10, interactive=False)
|
| 267 |
+
user_input.submit(chat, inputs=[user_input], outputs=[rena_response, avatar])
|
| 268 |
+
submit_button = gr.Button("Submit")
|
| 269 |
+
submit_button.click(chat, inputs=[user_input], outputs=[rena_response, avatar])
|
| 270 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
|
| 272 |
# Launch the app
|
| 273 |
interface.launch()
|
assets/emotions/angry2.png
DELETED
Git LFS Details
|
assets/emotions/angry3.png
DELETED
Git LFS Details
|
assets/emotions/angry4.png
DELETED
Git LFS Details
|
assets/emotions/angry5.png
DELETED
Git LFS Details
|
assets/emotions/angy.png
DELETED
Git LFS Details
|
assets/emotions/excited.png
DELETED
Git LFS Details
|
assets/emotions/excited2.png
DELETED
Git LFS Details
|
assets/emotions/flirty.png
DELETED
Git LFS Details
|
assets/emotions/flirty2.png
DELETED
Git LFS Details
|
assets/emotions/flirty3.png
DELETED
Git LFS Details
|
assets/emotions/flirty4.png
DELETED
Git LFS Details
|
assets/emotions/happy.png
DELETED
Git LFS Details
|
assets/emotions/thinking.png
DELETED
Git LFS Details
|
assets/emotions/thinking2.png
DELETED
Git LFS Details
|
assets/emotions/thinking3.png
DELETED
Git LFS Details
|
assets/emotions/upset.png
DELETED
Git LFS Details
|
assets/emotions/upset2.png
DELETED
Git LFS Details
|
assets/emotions/upset3.png
DELETED
Git LFS Details
|
assets/emotions/upset4.png
DELETED
Git LFS Details
|