Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,28 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
|
4 |
+
# Load the model and tokenizer
|
5 |
+
model_name = "models/meta-llama/Llama-3.3-70B-Instruct"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
+
|
9 |
+
def chat_with_model(user_input):
|
10 |
+
# Encode the user input and generate a response
|
11 |
+
inputs = tokenizer.encode(user_input, return_tensors="pt")
|
12 |
+
output = model.generate(inputs, max_length=150, num_return_sequences=1)
|
13 |
+
|
14 |
+
# Decode the generated response
|
15 |
+
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
16 |
+
return response
|
17 |
+
|
18 |
+
# Create a Gradio interface for chatting
|
19 |
+
iface = gr.Interface(
|
20 |
+
fn=chat_with_model,
|
21 |
+
inputs=gr.Textbox(label="You:"),
|
22 |
+
outputs=gr.Textbox(label="Bot:"),
|
23 |
+
title="Llama Chatbot",
|
24 |
+
description="Chat with Llama-3.3-70B-Instruct model."
|
25 |
+
)
|
26 |
+
|
27 |
+
# Launch the app
|
28 |
+
iface.launch()
|