import gradio as gr from transformers import pipeline # Load the GPT-2 model from Hugging Face using the pipeline generator = pipeline('text-generation', model='gpt2-medium') def generate_text(prompt, max_length=50): # Generate text using the GPT-2 model generated_text = generator(prompt, max_length=max_length, num_return_sequences=1)[0]['generated_text'] return generated_text # Create a Gradio interface iface = gr.Interface( fn=generate_text, inputs=[ gr.Textbox(lines=3, placeholder="Enter your prompt here...", label="Prompt"), gr.Slider(minimum=10, maximum=250, value=100, label="Max Length"), ], outputs=gr.Textbox(label="Generated Text"), title="GPT-2 Text Generator (OUTDATED)", description="Enter a prompt and generate text using GPT-2 on Hugging Face. Try out other models [here](https://huggingface.co/tchans123)." ) # Launch the Gradio interface iface.launch(share=True)