region:us
pip install transformers

from transformers import GPT2LMHeadModel, GPT2Tokenizer

tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
model = GPT2LMHeadModel.from_pretrained("gpt2")

from transformers import GPT2LMHeadModel, GPT2Tokenizer


# Encode input text
input_text = "Hello, how are you?"
input_ids = tokenizer.encode(input_text, return_tensors='pt')

# Generate text
output = model.generate(input_ids, max_length=100, temperature=0.7, num_return_sequences=1)

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

print(output_text)