Spaces:
No application file
No application file
SUSSYMANBI
commited on
Commit
•
a3af4de
1
Parent(s):
7591ced
asd
Browse files
test.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import GPT2Tokenizer, GPT2Model
|
2 |
+
|
3 |
+
# Load the tokenizer and model
|
4 |
+
tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
|
5 |
+
model = GPT2Model.from_pretrained('gpt2')
|
6 |
+
|
7 |
+
# Create a prompt
|
8 |
+
prompt = "I need a hug."
|
9 |
+
|
10 |
+
# Tokenize the prompt
|
11 |
+
inputs = tokenizer.encode(prompt, return_tensors='pt')
|
12 |
+
|
13 |
+
# Generate text using the model
|
14 |
+
outputs = model.generate(inputs, max_length=50, num_return_sequences=1)
|
15 |
+
|
16 |
+
# Decode the generated text
|
17 |
+
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
18 |
+
|
19 |
+
# Print the generated text
|
20 |
+
print(generated_text)
|