ahabb commited on
Commit
d47c47b
·
verified ·
1 Parent(s): c2f248d
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Initialize the text generation pipeline
5
+ generator = pipeline('text-generation', model='gpt2')
6
+
7
+ def generate_blogpost(topic, max_length=500):
8
+ prompt = f"Write a blog post about {topic}:\n\n"
9
+
10
+ # Generate the blog post
11
+ generated_text = generator(prompt, max_length=max_length, num_return_sequences=1)[0]['generated_text']
12
+
13
+ # Remove the prompt from the generated text
14
+ blog_post = generated_text[len(prompt):].strip()
15
+
16
+ return blog_post
17
+
18
+ # Create the Gradio interface
19
+ iface = gr.Interface(
20
+ fn=generate_blogpost,
21
+ inputs=[
22
+ gr.Textbox(lines=1, placeholder="Enter the blog post topic here..."),
23
+ gr.Slider(minimum=100, maximum=1000, step=50, label="Max Length", value=500)
24
+ ],
25
+ outputs="text",
26
+ title="Blog Post Generator",
27
+ description="Enter a topic, and this app will generate a blog post using GPT-2."
28
+ )
29
+
30
+ # Launch the app
31
+ iface.launch()