Spaces:
Runtime error
Runtime error
Commit ·
04ae961
1
Parent(s): 3be0569
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,15 @@ from PIL import Image
|
|
| 6 |
# Define the model name
|
| 7 |
model_name = "tiiuae/Falcon3-10b-instruct"
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
# Load the tokenizer and model
|
| 10 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 11 |
model = AutoModelForCausalLM.from_pretrained(
|
|
@@ -14,29 +23,40 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 14 |
device_map="auto"
|
| 15 |
)
|
| 16 |
|
| 17 |
-
|
| 18 |
rena_avatar = Image.open("assets/rena2.png")
|
| 19 |
|
| 20 |
-
@spaces.GPU
|
| 21 |
def chat(input_text):
|
| 22 |
-
#
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
| 24 |
outputs = model.generate(**inputs, max_new_tokens=100, do_sample=True)
|
| 25 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# Define the Gradio interface
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
# Launch the app
|
| 42 |
interface.launch()
|
|
|
|
| 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.
|
| 15 |
+
Respond to the following input:
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
# Load the tokenizer and model
|
| 19 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 20 |
model = AutoModelForCausalLM.from_pretrained(
|
|
|
|
| 23 |
device_map="auto"
|
| 24 |
)
|
| 25 |
|
| 26 |
+
# Load the Rena avatar
|
| 27 |
rena_avatar = Image.open("assets/rena2.png")
|
| 28 |
|
| 29 |
+
@spaces.GPU
|
| 30 |
def chat(input_text):
|
| 31 |
+
# Combine the base prompt with the user's input
|
| 32 |
+
final_prompt = base_prompt + f"\nUser: {input_text}\nRena:"
|
| 33 |
+
|
| 34 |
+
# Tokenize and generate a response
|
| 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():
|
| 53 |
+
user_input = gr.Textbox(label="Your Message", lines=2)
|
| 54 |
+
rena_response = gr.Textbox(label="Rena's Response", lines=10, interactive=False)
|
| 55 |
+
|
| 56 |
+
# Action button to submit input
|
| 57 |
+
with gr.Row():
|
| 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()
|