learningai commited on
Commit
e24c717
·
1 Parent(s): b9909cf

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ from transformers import AutoTokenizer
4
+ import transformers
5
+ import torch
6
+ from huggingface_hub import login
7
+
8
+ login(token="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")
9
+
10
+ model = "meta-llama/Llama-2-7b-chat-hf"
11
+
12
+ tokenizer = AutoTokenizer.from_pretrained(model)
13
+ pipeline = transformers.pipeline(
14
+ "text-generation",
15
+ model=model,
16
+ torch_dtype=torch.float16,
17
+ device_map="auto",
18
+ )
19
+
20
+ sequences = pipeline(
21
+ 'I liked "Breaking Bad" and "Band of Brothers". Do you have any recommendations of other shows I might like?\n',
22
+ do_sample=True,
23
+ top_k=10,
24
+ num_return_sequences=1,
25
+ eos_token_id=tokenizer.eos_token_id,
26
+ max_length=200,
27
+ )
28
+ for seq in sequences:
29
+ print(f"Result: {seq['generated_text']}")