# seo_blog_writer_app.py import gradio as gr import google.generativeai as genai import json from datetime import datetime import re import os # Example system prompt for Gemini SYSTEM_PROMPT = ''' You are an expert SEO blog writer for a fermentation-focused website. Write a long-form SEO blog post targeting the keyword: "{KEYWORD}". Use the following writing guidelines: - Tone: {TONE} (e.g., Informative, Conversational, Friendly) - Point of View: {POV} (e.g., Third Person, Second Person) - Audience: Beginners interested in fermentation Content structure: - Start with a compelling introduction (hook) - Use
{schema_content}
The generated content doesn't include FAQ structured data.
Error analyzing schema: {str(e)}
" # Create the Gradio interface with gr.Blocks(theme=gr.themes.Soft(), title="SEO Blog Generator") as demo: gr.Markdown(""" # 🧠 SEO Blog Article Generator Generate WordPress-ready blog content with metadata, FAQ, internal links, and schema using Gemini 1.5 Pro. **Quick Start:** 1. 🔑 Enter your Gemini API key 2. 🎯 Specify your target keyword 3. 📝 Choose tone and point of view 4. 🔗 Add internal links (optional) 5. 🚀 Click Generate! """) # API Key Section gr.Markdown("### 🔐 API Configuration") api_key_input = gr.Textbox( label="Gemini API Key", type="password", placeholder="Enter your Google Gemini API key...", info="Get your API key from Google AI Studio" ) # Content Settings gr.Markdown("### ⚙️ Content Settings") with gr.Row(): keyword_input = gr.Textbox( label="Target SEO Keyword", placeholder="e.g., how to ferment carrots at home", scale=2 ) tone_input = gr.Dropdown( ["Informative", "Conversational", "Friendly", "Professional"], value="Friendly", label="Writing Tone", scale=1 ) pov_input = gr.Dropdown( ["First Person", "Second Person", "Third Person"], value="Second Person", label="Point of View", scale=1 ) # Internal Links Section gr.Markdown("### 🔗 Internal Links (Optional)") internal_links_box = gr.Textbox( label="Internal Links", lines=3, placeholder="kefir:https://example.com/kefir-guide\nkombucha:https://example.com/kombucha-basics", info="Format: keyword:url (one per line)" ) # Generate Button generate_btn = gr.Button("🚀 Generate Blog Post", variant="primary", size="lg") # Results Section gr.Markdown("### 📊 Generated Content") with gr.Row(): with gr.Column(): result_html = gr.Textbox( label="Generated HTML Code", lines=12, info="Copy this HTML to use in WordPress", max_lines=20, show_copy_button=True ) with gr.Column(): preview_html = gr.HTML(label="Live Preview") # Analysis & Download gr.Markdown("### 🔍 Analysis & Download") with gr.Row(): with gr.Column(): faq_test = gr.HTML(label="Schema Analysis") with gr.Column(): download_file = gr.File( label="Download HTML File", interactive=False, visible=True ) # Event handlers generate_btn.click( fn=generate_blog, inputs=[api_key_input, keyword_input, tone_input, pov_input, internal_links_box], outputs=[result_html, preview_html, download_file] ) result_html.change( fn=test_faq_schema, inputs=[result_html], outputs=[faq_test] ) # Add examples gr.Markdown("### 💡 Example Inputs") gr.Examples( examples=[ ["how to ferment vegetables at home", "Conversational", "Second Person", "fermentation:https://example.com/fermentation-guide\nvegetables:https://example.com/vegetable-guide"], ["benefits of drinking kefir daily", "Informative", "Third Person", "kefir:https://example.com/kefir-guide\nprobiotics:https://example.com/probiotics-benefits"], ["making kombucha for beginners", "Friendly", "Second Person", "kombucha:https://example.com/kombucha-basics\nSCOBY:https://example.com/what-is-scoby"] ], inputs=[keyword_input, tone_input, pov_input, internal_links_box] ) if __name__ == "__main__": demo.launch( share=True, server_name="0.0.0.0", inbrowser=False, show_error=True, quiet=False )