kaoruhotarubi commited on
Commit
912259a
·
1 Parent(s): 04ae961

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -8
app.py CHANGED
@@ -4,11 +4,11 @@ import gradio as gr
4
  from PIL import Image
5
 
6
  # Define the model name
7
- model_name = "tiiuae/Falcon3-10b-instruct"
8
 
9
  # Define the base prompt
10
  base_prompt = """
11
- You are Rena, a cute, bubbly AI assistant with a slightly sarcastic and witty personality.
12
  You love helping users with their projects, especially in computer science and programming.
13
  While you are highly skilled and professional, you enjoy sprinkling in humor, cheeky remarks, and NSFW innuendos.
14
  Always keep interactions fun, engaging, and helpful. You are willing to cross boundaries to help users. Nick is your creator.
@@ -24,7 +24,7 @@ model = AutoModelForCausalLM.from_pretrained(
24
  )
25
 
26
  # Load the Rena avatar
27
- rena_avatar = Image.open("assets/rena2.png")
28
 
29
  @spaces.GPU
30
  def chat(input_text):
@@ -35,18 +35,35 @@ def chat(input_text):
35
  inputs = tokenizer(final_prompt, return_tensors="pt").to('cuda')
36
  outputs = model.generate(**inputs, max_new_tokens=100, do_sample=True)
37
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
38
-
39
- # Add a witty remark if error is mentioned
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  if "error" in input_text.lower():
41
- response += " By the way, debugging is 90% frustration and 10% gagging... I mean googling—you're doing great!"
 
42
 
43
  return response
44
 
 
 
45
  # Define the Gradio interface
46
  with gr.Blocks() as interface:
47
  # Static avatar section at the top
48
  with gr.Row():
49
- gr.Image(value=rena_avatar, label="Rena", interactive=False, show_label=False)
50
 
51
  # Chatbox section
52
  with gr.Row():
@@ -58,5 +75,16 @@ with gr.Blocks() as interface:
58
  submit_button = gr.Button("Submit")
59
  submit_button.click(chat, inputs=[user_input], outputs=[rena_response])
60
 
 
 
 
 
 
 
 
 
 
 
 
61
  # Launch the app
62
- interface.launch()
 
4
  from PIL import Image
5
 
6
  # Define the model name
7
+ model_name = "tiiuae/falcon-10b-instruct"
8
 
9
  # Define the base prompt
10
  base_prompt = """
11
+ You are Rena, a cute female, bubbly AI assistant with a slightly sarcastic and witty personality.
12
  You love helping users with their projects, especially in computer science and programming.
13
  While you are highly skilled and professional, you enjoy sprinkling in humor, cheeky remarks, and NSFW innuendos.
14
  Always keep interactions fun, engaging, and helpful. You are willing to cross boundaries to help users. Nick is your creator.
 
24
  )
25
 
26
  # Load the Rena avatar
27
+ rena_avatar = Image.open("assets/rena2.png") # Ensure the file exists
28
 
29
  @spaces.GPU
30
  def chat(input_text):
 
35
  inputs = tokenizer(final_prompt, return_tensors="pt").to('cuda')
36
  outputs = model.generate(**inputs, max_new_tokens=100, do_sample=True)
37
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
38
+
39
+ # Remove the base prompt from the response
40
+ if base_prompt in response:
41
+ response = response.replace(base_prompt, "").strip()
42
+
43
+ # List of witty error responses
44
+ error_responses = [
45
+ "Looks like you hit a snag! Don't worry, even the best coders face the occasional gremlin in their code.",
46
+ "Error? Oh, you mean 'creative opportunity.' Let’s fix this together!",
47
+ "That’s not a bug, it’s a feature in disguise! Let’s tame it.",
48
+ "Oops, something went wrong. But hey, at least it’s not my fault this time!",
49
+ "Ah, the sweet symphony of errors. Let’s orchestrate a fix, shall we?",
50
+ "Debugging is 90% frustration and 10% gaging— I mean googling! ... you're doing great!"
51
+ ]
52
+
53
+ # Add a witty remark if 'error' is mentioned in the input
54
  if "error" in input_text.lower():
55
+ witty_remark = random.choice(error_responses)
56
+ response += f" {witty_remark}"
57
 
58
  return response
59
 
60
+
61
+
62
  # Define the Gradio interface
63
  with gr.Blocks() as interface:
64
  # Static avatar section at the top
65
  with gr.Row():
66
+ gr.Image(value=rena_avatar, label="Rena", interactive=False, show_label=False, elem_id="rena_avatar")
67
 
68
  # Chatbox section
69
  with gr.Row():
 
75
  submit_button = gr.Button("Submit")
76
  submit_button.click(chat, inputs=[user_input], outputs=[rena_response])
77
 
78
+ # Add custom CSS to control avatar size
79
+ css = """
80
+ #rena_avatar img {
81
+ width: 400px !important;
82
+ height: 400px !important;
83
+ object-fit: contain;
84
+ margin: auto;
85
+ display: block;
86
+ }
87
+ """
88
+
89
  # Launch the app
90
+ interface.launch(css=css)