|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
generator = pipeline("text-generation", model="gpt2") |
|
|
|
def generate_blog_post(topic, keywords): |
|
prompt = f"Write an SEO-optimized blog post about {topic}. Include keywords: {', '.join(keywords)}." |
|
|
|
generated = generator(prompt, max_length=500, num_return_sequences=1) |
|
return generated[0]['generated_text'] |
|
|
|
|
|
def main(): |
|
with gr.Blocks() as demo: |
|
gr.Markdown("# Blog Post Generator") |
|
topic_input = gr.Textbox(label="Enter the blog topic", placeholder="e.g. Website Maintenance Tips") |
|
keywords_input = gr.Textbox(label="Enter keywords (comma-separated)", placeholder="e.g. website maintenance, SEO, content updates") |
|
|
|
generate_button = gr.Button("Generate Blog Post") |
|
output_area = gr.Textbox(label="Generated Blog Post", placeholder="Your blog post will appear here...", interactive=False) |
|
|
|
generate_button.click( |
|
fn=generate_blog_post, |
|
inputs=[topic_input, keywords_input], |
|
outputs=output_area |
|
) |
|
|
|
demo.launch() |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|