from transformers import GPT2LMHeadModel, GPT2Tokenizer
def generate_text(prompt, max_length=100):
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
model = GPT2LMHeadModel.from_pretrained("gpt2")
inputs = tokenizer.encode(prompt, return_tensors='pt')
outputs = model.generate(inputs, max_length=max_length, num_return_sequences=1)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
prompt = "こんにちは"
generated_text = generate_text(prompt)
print(generated_text)