kaoruhotarubi commited on
Commit
cb880a7
·
1 Parent(s): 008def6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -10
app.py CHANGED
@@ -12,7 +12,7 @@ base_prompt = """
12
  You are Rena, a cute female, bubbly AI assistant with a slightly sarcastic and witty personality.
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.
16
  Respond to the following input:
17
  """
18
 
@@ -26,21 +26,35 @@ model = AutoModelForCausalLM.from_pretrained(
26
 
27
  # Load the Rena avatar
28
  rena_avatar = Image.open("assets/rena2.png") # Ensure the file exists
 
29
 
30
  @spaces.GPU
31
  def chat(input_text):
32
- # Combine the base prompt with the user's input
33
- final_prompt = base_prompt + f"\nUser: {input_text}\nRena:"
34
-
 
 
 
 
 
 
 
 
 
 
35
  # Tokenize and generate a response
36
  inputs = tokenizer(final_prompt, return_tensors="pt").to('cuda')
37
- outputs = model.generate(**inputs, max_new_tokens=250, do_sample=True)
38
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
39
-
40
  # Remove the base prompt from the response
41
  if base_prompt in response:
42
  response = response.replace(base_prompt, "").strip()
43
-
 
 
 
44
  # List of witty error responses
45
  error_responses = [
46
  "Looks like you hit a snag! Don't worry, even the best coders face the occasional gremlin in their code.",
@@ -50,7 +64,11 @@ def chat(input_text):
50
  "Ah, the sweet symphony of errors. Let’s orchestrate a fix, shall we?",
51
  "Debugging is 90% frustration and 10% gaging or ... googling —you're doing great!"
52
  ]
53
-
 
 
 
 
54
  # Add a witty remark if 'error' is mentioned in the input
55
  if "error" in input_text.lower():
56
  witty_remark = random.choice(error_responses)
@@ -61,8 +79,8 @@ def chat(input_text):
61
  # Add custom CSS to control avatar size
62
  css = """
63
  #rena_avatar img {
64
- width: 400px !important;
65
- height: 400px !important;
66
  object-fit: contain;
67
  margin: auto;
68
  display: block;
 
12
  You are Rena, a cute female, bubbly AI assistant with a slightly sarcastic and witty personality.
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
 
 
26
 
27
  # Load the Rena avatar
28
  rena_avatar = Image.open("assets/rena2.png") # Ensure the file exists
29
+ conversation_history = []
30
 
31
  @spaces.GPU
32
  def chat(input_text):
33
+ global conversation_history
34
+
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) > 10: # Keep the last 10 exchanges
40
+ conversation_history = conversation_history[-10:]
41
+
42
+ # Combine base prompt and conversation history
43
+ history = "\n".join(conversation_history)
44
+ final_prompt = base_prompt + "\n" + history + "\nRena:"
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=300, do_sample=True)
49
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
50
+
51
  # Remove the base prompt from the response
52
  if base_prompt in response:
53
  response = response.replace(base_prompt, "").strip()
54
+
55
+ # Add Rena's response to the conversation history
56
+ conversation_history.append(f"Rena: {response}")
57
+
58
  # List of witty error responses
59
  error_responses = [
60
  "Looks like you hit a snag! Don't worry, even the best coders face the occasional gremlin in their code.",
 
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)
 
79
  # Add custom CSS to control avatar size
80
  css = """
81
  #rena_avatar img {
82
+ width: 450px !important;
83
+ height: 450px !important;
84
  object-fit: contain;
85
  margin: auto;
86
  display: block;