Spaces:
Build error
Build error
| import gradio as gr | |
| from transformers import pipeline | |
| # Load the GPT-2 text generation pipeline | |
| generator = pipeline("text-generation", model="gpt2") | |
| def generate_text(prompt): | |
| # Generate text | |
| outputs = generator(prompt, max_length=100, num_return_sequences=1) | |
| # Extract the generated text | |
| text = outputs[0]['generated_text'] | |
| return text | |
| # Set up the Gradio interface with dynamic generation | |
| iface = gr.Interface( | |
| fn=generate_text, | |
| inputs=gr.Textbox(label="Enter Prompt", placeholder="Type your prompt here..."), | |
| outputs=gr.Textbox(label="Generated Text"), | |
| title="GPT-2 Text Generator", | |
| description="Enter a prompt to generate text using GPT-2 small. The text will update dynamically as you type." | |
| ) | |
| # Launch the app | |
| iface.launch(share=True) | |