region:us
from transformers import GPT2LMHeadModel, GPT2Tokenizer

def load_model():
    model_name = "gpt2"  # You can experiment with other GPT-2 variants or models
    model = GPT2LMHeadModel.from_pretrained(model_name)
    tokenizer = GPT2Tokenizer.from_pretrained(model_name)
    return model, tokenizer

def generate_response(prompt, model, tokenizer, max_length=100):
    input_ids = tokenizer.encode(prompt, return_tensors="pt")

    # Generate response
    output = model.generate(input_ids, max_length=max_length, num_beams=5, no_repeat_ngram_size=2, top_k=50, top_p=0.95, temperature=0.7)

    response = tokenizer.decode(output[0], skip_special_tokens=True)
    return response

if __name__ == "__main__":
    model, tokenizer = load_model()

    while True:
        user_input = input("You: ")
        if user_input.lower() == 'exit':
            break

        response = generate_response(user_input, model, tokenizer)
        print("Bot:", response)
