Mo-alaa commited on
Commit
f41f56e
·
1 Parent(s): edbbd82

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForCausalLM, AutoTokenizer
2
+
3
+ device = "cuda" # 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])