import gradio as gr from transformers import pipeline # Load a text generation pipeline from Hugging Face generator = pipeline("text-generation", model="gpt2") def chat_with_model(prompt): result = generator(prompt, max_length=100)[0]['generated_text'] return result # Build Gradio interface iface = gr.Interface( fn=chat_with_model, inputs=gr.Textbox(lines=2, placeholder="Type your message..."), outputs="text", title="My AI Chatbot", description="Chat with a GPT-2 model!" ) iface.launch()