Update app.py
Browse files
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
|