Spaces:
Runtime error
Runtime error
LovnishVerma
commited on
Commit
•
46c8cfc
1
Parent(s):
ff9f2fc
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,32 @@
|
|
1 |
-
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
)
|
15 |
|
16 |
-
#
|
17 |
-
|
|
|
|
1 |
+
# Install necessary libraries
|
2 |
+
# !pip install transformers
|
3 |
|
4 |
+
from transformers import AutoTokenizer, pipeline
|
5 |
+
import torch
|
6 |
|
7 |
+
# Model and prompt details
|
8 |
+
model_name = "mlabonne/llama-2-7b-guanaco"
|
9 |
+
prompt = "What is a large language model?"
|
10 |
+
|
11 |
+
# Load tokenizer and pipeline
|
12 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
13 |
+
text_generation_pipeline = pipeline(
|
14 |
+
"text-generation",
|
15 |
+
model=model_name,
|
16 |
+
torch_dtype=torch.float16,
|
17 |
+
device_map="auto",
|
18 |
+
)
|
19 |
+
|
20 |
+
# Generate text using the provided prompt
|
21 |
+
sequences = text_generation_pipeline(
|
22 |
+
f'<s>[INST] {prompt} [/INST]',
|
23 |
+
do_sample=True,
|
24 |
+
top_k=10,
|
25 |
+
num_return_sequences=1,
|
26 |
+
eos_token_id=tokenizer.eos_token_id,
|
27 |
+
max_length=200,
|
28 |
)
|
29 |
|
30 |
+
# Print the generated text
|
31 |
+
for seq in sequences:
|
32 |
+
print(f"Generated Text: {seq['generated_text']}")
|