Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,20 @@
|
|
1 |
-
|
2 |
-
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
3 |
|
4 |
-
|
5 |
-
|
|
|
6 |
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
st.json(out)
|
|
|
1 |
+
!pip install -qU transformers accelerate
|
|
|
2 |
|
3 |
+
from transformers import AutoTokenizer
|
4 |
+
import transformers
|
5 |
+
import torch
|
6 |
|
7 |
+
model = "mlabonne/NeuralBeagle14-7B"
|
8 |
+
messages = [{"role": "user", "content": "What is a large language model?"}]
|
9 |
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(model)
|
11 |
+
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
12 |
+
pipeline = transformers.pipeline(
|
13 |
+
"text-generation",
|
14 |
+
model=model,
|
15 |
+
torch_dtype=torch.float16,
|
16 |
+
device_map="auto",
|
17 |
+
)
|
18 |
|
19 |
+
outputs = pipeline(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
|
20 |
+
print(outputs[0]["generated_text"])
|
|