import gradio as gr from transformers import pipeline # Initialize the text generation pipeline generator = pipeline('text-generation', model='gpt2') def generate_blogpost(topic, max_length=500): prompt = f"Write a blog post about {topic}:\n\n" # Generate the blog post generated_text = generator(prompt, max_length=max_length, num_return_sequences=1)[0]['generated_text'] # Remove the prompt from the generated text blog_post = generated_text[len(prompt):].strip() return blog_post # Create the Gradio interface iface = gr.Interface( fn=generate_blogpost, inputs=[ gr.Textbox(lines=1, placeholder="Enter the blog post topic here..."), gr.Slider(minimum=100, maximum=1000, step=50, label="Max Length", value=500) ], outputs="text", title="Blog Post Generator", description="Enter a topic, and this app will generate a blog post using GPT-2." ) # Launch the app iface.launch()