import gradio as gr from transformers import pipeline # Load a pre-trained Hugging Face model generator = pipeline("text-generation", model="gpt2") def generate_text(prompt): # Generate text using the model result = generator(prompt, max_length=50, num_return_sequences=1) return result[0]["generated_text"] # Create the Gradio interface iface = gr.Interface( fn=generate_text, inputs=gr.Textbox(lines=2, placeholder="Enter your prompt here..."), outputs=gr.Textbox() ) # Launch the interface iface.launch()