import gradio as gr from transformers import pipeline # Load the text generation pipeline from Hugging Face generator = pipeline("text-generation", model="gpt-2") def generate_text(prompt): # Generate text based on the input prompt results = generator(prompt, max_length=100, num_return_sequences=1) return results[0]['generated_text'] # Create the Gradio interface iface = gr.Interface( fn=generate_text, inputs=gr.inputs.Textbox(label="Input Prompt", lines=2, placeholder="Enter your prompt here..."), outputs=gr.outputs.Textbox(label="Generated Text"), title="Text Generation with GPT-2", description="Enter a prompt and get a generated text using the GPT-2 model from Hugging Face." ) # Launch the interface iface.launch()