Paulhayes commited on
Commit
909114b
·
verified ·
1 Parent(s): 31d7760

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py CHANGED
@@ -1,4 +1,23 @@
1
  # === BOOTSTRAP + SAFE DATASETS SHIM (must be line 1) =========================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import os, sys, subprocess, importlib.util, importlib.machinery, types
3
  import sys # make sure this import is near the top of your file
4
  # near the other imports
 
1
  # === BOOTSTRAP + SAFE DATASETS SHIM (must be line 1) =========================
2
+ # Load model directly
3
+ from transformers import AutoTokenizer, AutoModelForCausalLM
4
+
5
+ tokenizer = AutoTokenizer.from_pretrained("TinyLlama/TinyLlama-1.1B-Chat-v1.0")
6
+ model = AutoModelForCausalLM.from_pretrained("TinyLlama/TinyLlama-1.1B-Chat-v1.0")
7
+ messages = [
8
+ {"role": "user", "content": "Who are you?"},
9
+ ]
10
+ inputs = tokenizer.apply_chat_template(
11
+ messages,
12
+ add_generation_prompt=True,
13
+ tokenize=True,
14
+ return_dict=True,
15
+ return_tensors="pt",
16
+ ).to(model.device)
17
+
18
+ outputs = model.generate(**inputs, max_new_tokens=40)
19
+ print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))
20
+
21
  import os, sys, subprocess, importlib.util, importlib.machinery, types
22
  import sys # make sure this import is near the top of your file
23
  # near the other imports