File size: 958 Bytes
d47c47b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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()