kaoruhotarubi commited on
Commit
77ae8b5
·
1 Parent(s): dcfb254

added dynamic avatar changes

Browse files
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=rena_avatar, label="Rena", interactive=False, show_label=False, elem_id="rena_avatar")
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

  • SHA256: 17bab933563450183589f2ec1f8930d93336ab60256620c6b6481a5683b1ec4b
  • Pointer size: 132 Bytes
  • Size of remote file: 1.92 MB
assets/emotions/angry3.png DELETED

Git LFS Details

  • SHA256: 7cd5a82540aa2358cfe2cdafb7f5d691e17cc08393df9252a094e5b96332d48f
  • Pointer size: 132 Bytes
  • Size of remote file: 2.03 MB
assets/emotions/angry4.png DELETED

Git LFS Details

  • SHA256: 9dad81ecf852ffd8797dc2b179b7b3433b316d8bafb9f4b4140ea3d001e2b782
  • Pointer size: 132 Bytes
  • Size of remote file: 1.92 MB
assets/emotions/angry5.png DELETED

Git LFS Details

  • SHA256: bdab652add0ba67cbc26fbad67137cc048a1d6ca452b740b875d27bd01cc19a9
  • Pointer size: 132 Bytes
  • Size of remote file: 1.95 MB
assets/emotions/angy.png DELETED

Git LFS Details

  • SHA256: 9cabde5183e3da6e6f9385fd8d9fe063afc1b960c156150ace2f1c12da02763a
  • Pointer size: 132 Bytes
  • Size of remote file: 1.95 MB
assets/emotions/excited.png DELETED

Git LFS Details

  • SHA256: 5d877b8fbd6424f9991fdc78aba96974bb8b291bc2cd65d4b2abe67e04f20210
  • Pointer size: 132 Bytes
  • Size of remote file: 2.06 MB
assets/emotions/excited2.png DELETED

Git LFS Details

  • SHA256: dd9d1863a2c3840da4c34b86976ed17981da1a6aba8588ad2d5dcdce4432e989
  • Pointer size: 132 Bytes
  • Size of remote file: 2.21 MB
assets/emotions/flirty.png DELETED

Git LFS Details

  • SHA256: d5f5e3abdcf04537c2a8cc3e8432829f63ca31c5de58bdaf5bc28b911e42fd7e
  • Pointer size: 132 Bytes
  • Size of remote file: 1.99 MB
assets/emotions/flirty2.png DELETED

Git LFS Details

  • SHA256: 593c07e8f3d2354d0e698d8caf5e8b2e292faf15c62e3d5d2f2bc418be495faf
  • Pointer size: 132 Bytes
  • Size of remote file: 2.08 MB
assets/emotions/flirty3.png DELETED

Git LFS Details

  • SHA256: ea7b7ec39fda2e98d0a10f128bf75bff7ee8fd5272196dac8ff1a2ee6da11a65
  • Pointer size: 132 Bytes
  • Size of remote file: 2.15 MB
assets/emotions/flirty4.png DELETED

Git LFS Details

  • SHA256: 2b690287641111ff52b91184f3b31bf36d16b5dfb26726456f08b5f6db4629b1
  • Pointer size: 132 Bytes
  • Size of remote file: 2.16 MB
assets/emotions/happy.png DELETED

Git LFS Details

  • SHA256: cfe79a3b53cf1bc4715a44313e11ff3b2bd5fdac1960143730cfcf5969836020
  • Pointer size: 132 Bytes
  • Size of remote file: 2.12 MB
assets/emotions/thinking.png DELETED

Git LFS Details

  • SHA256: 1ce7942f6afc674dcfb9f8a66e3d6bf5f83144a6aceaad362b08ed4ba4bb4b9d
  • Pointer size: 132 Bytes
  • Size of remote file: 2.03 MB
assets/emotions/thinking2.png DELETED

Git LFS Details

  • SHA256: a071158eba44264f17e584caaa9db5157f7bf623acba30aaf8cbf93566fcb20d
  • Pointer size: 132 Bytes
  • Size of remote file: 2.13 MB
assets/emotions/thinking3.png DELETED

Git LFS Details

  • SHA256: 6dbba884b7f98cc4683a40f9b3f10310c6effee271ba75efb2d714d6f590f607
  • Pointer size: 132 Bytes
  • Size of remote file: 2.08 MB
assets/emotions/upset.png DELETED

Git LFS Details

  • SHA256: 6bbfd4e892b33f01c3953fd4c337291171d000fa1622c41b47618bb1d173fe37
  • Pointer size: 132 Bytes
  • Size of remote file: 1.99 MB
assets/emotions/upset2.png DELETED

Git LFS Details

  • SHA256: f72da818094d2f13a9bcfce21945324f81686f4db19615537c118a4ed936a16f
  • Pointer size: 132 Bytes
  • Size of remote file: 1.79 MB
assets/emotions/upset3.png DELETED

Git LFS Details

  • SHA256: d7860e0c8968490924e0f52de0096fee82cefc9cc62f26f531f7d1c276a39257
  • Pointer size: 132 Bytes
  • Size of remote file: 1.88 MB
assets/emotions/upset4.png DELETED

Git LFS Details

  • SHA256: eeda769ff4a23db566bf2a36c0eaff9f73fc78c2670bf0bd1c76fc57f570d3d2
  • Pointer size: 132 Bytes
  • Size of remote file: 1.83 MB