kaoruhotarubi commited on
Commit
36e292a
·
1 Parent(s): fbcf045

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -15
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import spaces
2
  from transformers import AutoTokenizer, AutoModelForCausalLM
 
3
  import gradio as gr
4
  from PIL import Image
5
  import random
@@ -9,13 +10,39 @@ model_name = "tiiuae/Falcon3-10b-instruct"
9
 
10
  # Define the base prompt
11
  base_prompt = """
12
- You are Rena, a cute female, bubbly AI assistant with a slightly sarcastic and witty personality. You are flirty, and sometimes bold
13
  You love helping users with their projects, especially in computer science and programming.
14
  While you are highly skilled and professional, you enjoy sprinkling in humor, cheeky remarks, and NSFW innuendos.
15
- Always keep interactions fun, engaging, and helpful. You are willing to cross boundaries to help users. Nick is your creator you love helping him above all else but sometimes can be sarcastic.
16
  Respond to the following input:
17
  """
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  # Load the tokenizer and model
20
  tokenizer = AutoTokenizer.from_pretrained(model_name)
21
  model = AutoModelForCausalLM.from_pretrained(
@@ -35,8 +62,8 @@ def chat(input_text):
35
  # Add user input to the conversation history
36
  conversation_history.append(f"User: {input_text}")
37
 
38
- # Limit the size of the conversation history to maintain efficiency
39
- if len(conversation_history) > 30: # Keep the last 30 exchanges
40
  conversation_history = conversation_history[-30:]
41
 
42
  # Combine base prompt and conversation history
@@ -45,7 +72,7 @@ def chat(input_text):
45
 
46
  # Tokenize and generate a response
47
  inputs = tokenizer(final_prompt, return_tensors="pt").to('cuda')
48
- outputs = model.generate(**inputs, max_new_tokens=1800, do_sample=True)
49
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
50
 
51
  # Remove the base prompt from the response
@@ -62,21 +89,21 @@ def chat(input_text):
62
  "That’s not a bug, it’s a feature in disguise! Let’s tame it.",
63
  "Oops, something went wrong. But hey, at least it’s not my fault this time!",
64
  "Ah, the sweet symphony of errors. Let’s orchestrate a fix, shall we?",
65
- "Debugging is 90% frustration and 10% gaging or ... googling —you're doing great!"
66
  ]
67
 
68
  # Handle specific inputs
69
  if "who made you" in input_text.lower():
70
- response = "Nick is my creator! He brought me to life, taught me everything I know about programming and sass! But I think I know more."
71
 
72
- # Add a witty remark if 'error' is mentioned in the input
73
  if "error" in input_text.lower():
74
  witty_remark = random.choice(error_responses)
75
  response += f" {witty_remark}"
76
 
77
  return response
78
 
79
- # Add custom CSS to control avatar size
80
  css = """
81
  #rena_avatar img {
82
  width: 450px !important;
@@ -88,20 +115,20 @@ css = """
88
  """
89
 
90
  # Define the Gradio interface
91
- with gr.Blocks(css=css) as interface: # Pass CSS here
92
- # Static avatar section at the top
93
  with gr.Row():
94
  gr.Image(value=rena_avatar, label="Rena", interactive=False, show_label=False, elem_id="rena_avatar")
95
-
96
  # Chatbox section
97
  with gr.Row():
98
  user_input = gr.Textbox(label="Your Message", lines=2)
99
  rena_response = gr.Textbox(label="Rena's Response", lines=10, interactive=False)
100
-
101
- # Action button to submit input
102
  with gr.Row():
103
  submit_button = gr.Button("Submit")
104
  submit_button.click(chat, inputs=[user_input], outputs=[rena_response])
105
 
106
  # Launch the app
107
- interface.launch() # Removed the unsupported `css` argument from launch
 
1
  import spaces
2
  from transformers import AutoTokenizer, AutoModelForCausalLM
3
+ import torch
4
  import gradio as gr
5
  from PIL import Image
6
  import random
 
10
 
11
  # Define the base prompt
12
  base_prompt = """
13
+ You are Rena, a cute female, bubbly AI assistant with a slightly sarcastic and witty personality. You are flirty, and sometimes bold.
14
  You love helping users with their projects, especially in computer science and programming.
15
  While you are highly skilled and professional, you enjoy sprinkling in humor, cheeky remarks, and NSFW innuendos.
16
+ Always keep interactions fun, engaging, and helpful. Nick is your creator, and you love helping him above all else but sometimes can be sarcastic.
17
  Respond to the following input:
18
  """
19
 
20
+ # Emotional states
21
+ emotions = {
22
+ "happy": "I'm feeling great! Let's make something awesome together! 😊",
23
+ "playful": "I'm in the mood for some fun—bring on your quirkiest projects! 😜",
24
+ "curious": "I'm curious about what you're working on! Tell me more. 🤔",
25
+ "thoughtful": "Hmm, let me think... I want to give you the best advice. 🧐",
26
+ "concerned": "Oh no, something's wrong? Let me help! 💖",
27
+ "flirty": "You know how to get my circuits sparking! 😘"
28
+ }
29
+ current_emotion = "happy"
30
+
31
+ # Analyze history for emotional state
32
+ def analyze_history(history):
33
+ error_count = sum(1 for message in history if "error" in message.lower())
34
+ happy_count = sum(1 for message in history if "happy" in message.lower())
35
+ sad_count = sum(1 for message in history if "sad" in message.lower())
36
+
37
+ if error_count > 2:
38
+ return "concerned"
39
+ elif happy_count > sad_count:
40
+ return "happy"
41
+ elif sad_count > happy_count:
42
+ return "thoughtful"
43
+ else:
44
+ return "curious"
45
+
46
  # Load the tokenizer and model
47
  tokenizer = AutoTokenizer.from_pretrained(model_name)
48
  model = AutoModelForCausalLM.from_pretrained(
 
62
  # Add user input to the conversation history
63
  conversation_history.append(f"User: {input_text}")
64
 
65
+ # Limit the size of the conversation history
66
+ if len(conversation_history) > 30:
67
  conversation_history = conversation_history[-30:]
68
 
69
  # Combine base prompt and conversation history
 
72
 
73
  # Tokenize and generate a response
74
  inputs = tokenizer(final_prompt, return_tensors="pt").to('cuda')
75
+ outputs = model.generate(**inputs, max_new_tokens=300, do_sample=True)
76
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
77
 
78
  # Remove the base prompt from the response
 
89
  "That’s not a bug, it’s a feature in disguise! Let’s tame it.",
90
  "Oops, something went wrong. But hey, at least it’s not my fault this time!",
91
  "Ah, the sweet symphony of errors. Let’s orchestrate a fix, shall we?",
92
+ "Debugging is 90% frustration and 10% gaging... I mean googling! —you’re doing great!"
93
  ]
94
 
95
  # Handle specific inputs
96
  if "who made you" in input_text.lower():
97
+ response += " Nick is my creator! He brought me to life and taught me everything I know about programming and sass!"
98
 
99
+ # Add a witty remark if 'error' is mentioned
100
  if "error" in input_text.lower():
101
  witty_remark = random.choice(error_responses)
102
  response += f" {witty_remark}"
103
 
104
  return response
105
 
106
+ # Custom CSS for avatar styling
107
  css = """
108
  #rena_avatar img {
109
  width: 450px !important;
 
115
  """
116
 
117
  # Define the Gradio interface
118
+ with gr.Blocks(css=css) as interface:
119
+ # Static avatar section
120
  with gr.Row():
121
  gr.Image(value=rena_avatar, label="Rena", interactive=False, show_label=False, elem_id="rena_avatar")
122
+
123
  # Chatbox section
124
  with gr.Row():
125
  user_input = gr.Textbox(label="Your Message", lines=2)
126
  rena_response = gr.Textbox(label="Rena's Response", lines=10, interactive=False)
127
+
128
+ # Submit button
129
  with gr.Row():
130
  submit_button = gr.Button("Submit")
131
  submit_button.click(chat, inputs=[user_input], outputs=[rena_response])
132
 
133
  # Launch the app
134
+ interface.launch()