Spaces:
Runtime error
Runtime error
Commit
·
8e7f191
1
Parent(s):
a148356
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,29 @@
|
|
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
2 |
import gradio as gr
|
3 |
+
import torch
|
4 |
|
5 |
+
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-70b-chat-hf")
|
7 |
+
model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-2-70b-chat-hf")
|
8 |
+
|
9 |
+
|
10 |
+
def launch(input, history = []):
|
11 |
+
new_user_input_ids = tokenizer.encode(
|
12 |
+
input + tokenizer.eos_token, return_tensors="pt"
|
13 |
+
)
|
14 |
+
|
15 |
+
bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)
|
16 |
+
|
17 |
+
history = model.generate(
|
18 |
+
bot_input_ids, max_length=4000, pad_token_id=tokenizer.eos_token_id
|
19 |
+
).tolist()
|
20 |
+
|
21 |
+
response = tokenizer.decode(history[0]).split("<|endoftext|>")
|
22 |
+
response = [
|
23 |
+
(response[i], response[i + 1]) for i in range(0, len(response) - 1, 2)
|
24 |
+
]
|
25 |
+
return response
|
26 |
+
|
27 |
+
|
28 |
+
iface = gr.Interface(launch, inputs="text", outputs="text")
|
29 |
+
iface.launch()
|