Facegenerator / app.py
Yori6789's picture
1
b4ca10c
raw
history blame contribute delete
612 Bytes
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)