Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,21 @@
|
|
| 1 |
-
from transformers import AutoModelForCausalLM
|
| 2 |
-
|
|
|
|
|
|
|
| 3 |
model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
print(
|
|
|
|
| 1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 2 |
+
|
| 3 |
+
device = "cpu" # the device to load the model onto
|
| 4 |
+
|
| 5 |
model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
|
| 7 |
+
|
| 8 |
+
messages = [
|
| 9 |
+
{"role": "user", "content": "What is your favourite condiment?"},
|
| 10 |
+
{"role": "assistant", "content": "Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!"},
|
| 11 |
+
{"role": "user", "content": "Do you have mayonnaise recipes?"}
|
| 12 |
+
]
|
| 13 |
+
|
| 14 |
+
encodeds = tokenizer.apply_chat_template(messages, return_tensors="pt")
|
| 15 |
+
|
| 16 |
+
model_inputs = encodeds.to(device)
|
| 17 |
+
model.to(device)
|
| 18 |
|
| 19 |
+
generated_ids = model.generate(model_inputs, max_new_tokens=1000, do_sample=True)
|
| 20 |
+
decoded = tokenizer.batch_decode(generated_ids)
|
| 21 |
+
print(decoded[0])
|