Spaces:
Build error
Build error
Commit
·
6c86139
1
Parent(s):
3b5a452
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Import libraries
|
2 |
+
import gradio as gr
|
3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
+
|
5 |
+
# Load model and tokenizer
|
6 |
+
model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-2-70b-chat-hf")
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-70b-chat-hf")
|
8 |
+
|
9 |
+
# Define a function to generate responses
|
10 |
+
def chatbot(text):
|
11 |
+
# Encode the input text
|
12 |
+
input_ids = tokenizer.encode(text + tokenizer.eos_token, return_tensors="pt")
|
13 |
+
# Generate a response
|
14 |
+
output_ids = model.generate(input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id)
|
15 |
+
# Decode the output
|
16 |
+
output_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
17 |
+
# Return the output text
|
18 |
+
return output_text
|
19 |
+
|
20 |
+
# Create a web interface
|
21 |
+
iface = gr.Interface(chatbot, "textbox", "text", examples=[["Hello"], ["How are you?"], ["What is your name?"]])
|
22 |
+
# Launch the interface
|
23 |
+
iface.launch()
|
24 |
+
|