File size: 612 Bytes
b4ca10c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from transformers import GPT2Tokenizer, GPT2LMHeadModel
import torch

# Initialize the tokenizer and model
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
model = GPT2LMHeadModel.from_pretrained("gpt2")

# Set the model to evaluation mode
model.eval()

# Prompt text
prompt = "face generating code"

# Encode the prompt text
input_ids = tokenizer.encode(prompt, return_tensors="pt")

# Generate text
with torch.no_grad():
    output = model.generate(input_ids=input_ids, max_length=500)

# Decode the generated text
generated_text = tokenizer.decode(output[0], skip_special_tokens=True)

print(generated_text)