Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,179 +1,4 @@
|
|
| 1 |
-
|
| 2 |
-
with gr.Blocks(title="Fermentation SEO Assistant", theme=custom_theme, css="""
|
| 3 |
-
#seo-output-container {
|
| 4 |
-
min-height: 300px;
|
| 5 |
-
max-height: 800px;
|
| 6 |
-
overflow-y: auto;
|
| 7 |
-
border-left: 4px solid #84cc16;
|
| 8 |
-
padding-left: 15px;
|
| 9 |
-
background-color: #f8fafc;
|
| 10 |
-
border-radius: 6px;
|
| 11 |
-
transition: all 0.3s ease;
|
| 12 |
-
}
|
| 13 |
-
|
| 14 |
-
#seo-output-container:empty {
|
| 15 |
-
border-left-color: #e5e7eb;
|
| 16 |
-
background-color: #ffffff;
|
| 17 |
-
}
|
| 18 |
-
|
| 19 |
-
.loading-spinner {
|
| 20 |
-
display: inline-block;
|
| 21 |
-
width: 50px;
|
| 22 |
-
height: 50px;
|
| 23 |
-
border: 3px solid rgba(0,0,0,.3);
|
| 24 |
-
border-radius: 50%;
|
| 25 |
-
border-top-color: #84cc16;
|
| 26 |
-
animation: spin 1s ease-in-out infinite;
|
| 27 |
-
}
|
| 28 |
-
|
| 29 |
-
@keyframes spin {
|
| 30 |
-
to { transform: rotate(360deg); }
|
| 31 |
-
}
|
| 32 |
-
|
| 33 |
-
.tab-selected {
|
| 34 |
-
border-bottom: 3px solid #84cc16 !important;
|
| 35 |
-
font-weight: bold;
|
| 36 |
-
}
|
| 37 |
-
""") as app:
|
| 38 |
-
# Header
|
| 39 |
-
gr.Markdown("""
|
| 40 |
-
# 🌱 Advanced Food Blog SEO Content Planner
|
| 41 |
-
|
| 42 |
-
Generate comprehensive SEO plans for your food blog posts using Google's Gemini 1.5 Pro.
|
| 43 |
-
""")
|
| 44 |
-
|
| 45 |
-
# Create tabs for different sections
|
| 46 |
-
with gr.Tabs() as tabs:
|
| 47 |
-
# Main Generator Tab
|
| 48 |
-
with gr.TabItem("SEO Generator", id="generator_tab"):
|
| 49 |
-
# API Key & Configuration Section
|
| 50 |
-
with gr.Accordion("API Key & Settings", open=False):
|
| 51 |
-
with gr.Row():
|
| 52 |
-
api_key_input = gr.Textbox(
|
| 53 |
-
label="Gemini API Key",
|
| 54 |
-
placeholder="Enter your Google Gemini API key",
|
| 55 |
-
value=os.getenv("GEMINI_API_KEY", ""),
|
| 56 |
-
type="password"
|
| 57 |
-
)
|
| 58 |
-
save_btn = gr.Button("💾 Save Key")
|
| 59 |
-
|
| 60 |
-
with gr.Row():
|
| 61 |
-
temperature = gr.Slider(
|
| 62 |
-
minimum=0.0,
|
| 63 |
-
maximum=1.0,
|
| 64 |
-
value=0.7,
|
| 65 |
-
step=0.1,
|
| 66 |
-
label="Temperature (Creativity)",
|
| 67 |
-
info="Higher values = more creative, Lower values = more focused"
|
| 68 |
-
)
|
| 69 |
-
max_tokens = gr.Slider(
|
| 70 |
-
minimum=1000,
|
| 71 |
-
maximum=8000,
|
| 72 |
-
value=4000,
|
| 73 |
-
step=500,
|
| 74 |
-
label="Max Output Length",
|
| 75 |
-
info="Maximum number of tokens in the response"
|
| 76 |
-
)
|
| 77 |
-
|
| 78 |
-
save_btn.click(fn=save_api_key, inputs=api_key_input, outputs=gr.Textbox(label="Status"))
|
| 79 |
-
|
| 80 |
-
# Main content
|
| 81 |
-
with gr.Row():
|
| 82 |
-
with gr.Column(scale=1):
|
| 83 |
-
# Input section
|
| 84 |
-
topic_input = gr.Textbox(
|
| 85 |
-
label="🌶️ Your Food Topic",
|
| 86 |
-
placeholder="e.g., How to Make Kimchi at Home",
|
| 87 |
-
lines=2
|
| 88 |
-
)
|
| 89 |
-
|
| 90 |
-
# Template and language selectors
|
| 91 |
-
template_dropdown = gr.Dropdown(
|
| 92 |
-
choices=list(TEMPLATES.keys()),
|
| 93 |
-
value="fermentation",
|
| 94 |
-
label="Content Template",
|
| 95 |
-
info="Choose a specialized template for your food niche"
|
| 96 |
-
)
|
| 97 |
-
|
| 98 |
-
language_dropdown = gr.Dropdown(
|
| 99 |
-
choices=list(LANGUAGES.keys()),
|
| 100 |
-
value="English",
|
| 101 |
-
label="Target Language",
|
| 102 |
-
info="Optimize keywords for a specific language"
|
| 103 |
-
)
|
| 104 |
-
|
| 105 |
-
with gr.Row():
|
| 106 |
-
generate_btn = gr.Button("✨ Generate SEO Plan", variant="primary")
|
| 107 |
-
clear_btn = gr.Button("🔄 Clear", variant="secondary")
|
| 108 |
-
|
| 109 |
-
# Example topics for quick selection
|
| 110 |
-
gr.Examples(
|
| 111 |
-
examples=[
|
| 112 |
-
"Beginner's Guide to Fermenting Vegetables",
|
| 113 |
-
"How to Make Kombucha at Home",
|
| 114 |
-
"The Health Benefits of Fermented Foods",
|
| 115 |
-
"Wild Fermentation: Using Natural Yeasts and Bacteria",
|
| 116 |
-
"Troubleshooting Common Fermentation Problems"
|
| 117 |
-
],
|
| 118 |
-
inputs=topic_input,
|
| 119 |
-
label="Example Topics"
|
| 120 |
-
)
|
| 121 |
-
|
| 122 |
-
with gr.Column(scale=2):
|
| 123 |
-
# Output section with a visually appealing container
|
| 124 |
-
with gr.Group():
|
| 125 |
-
output_header = gr.Markdown("### Your SEO Plan Will Appear Here")
|
| 126 |
-
# Add progress indicator
|
| 127 |
-
progress_bar = gr.Progress(track_tqdm=True)
|
| 128 |
-
seo_output = gr.Markdown(elem_id="seo-output-container")
|
| 129 |
-
|
| 130 |
-
# Export button
|
| 131 |
-
with gr.Row():
|
| 132 |
-
export_html_btn = gr.Button("📄 Export as HTML", variant="secondary")
|
| 133 |
-
export_status = gr.Textbox(label="Export Status", interactive=False)
|
| 134 |
-
|
| 135 |
-
# Button actions for main tab
|
| 136 |
-
generate_btn.click(
|
| 137 |
-
fn=generate_seo_plan,
|
| 138 |
-
inputs=[topic_input, api_key_input, template_dropdown, language_dropdown, temperature, max_tokens],
|
| 139 |
-
outputs=seo_output,
|
| 140 |
-
api_name="generate",
|
| 141 |
-
show_progress="full"
|
| 142 |
-
)
|
| 143 |
-
|
| 144 |
-
clear_btn.click(
|
| 145 |
-
fn=clear_outputs,
|
| 146 |
-
inputs=None,
|
| 147 |
-
outputs=[topic_input, seo_output]
|
| 148 |
-
)
|
| 149 |
-
|
| 150 |
-
export_html_btn.click(
|
| 151 |
-
fn=export_html,
|
| 152 |
-
inputs=[seo_output, topic_input],
|
| 153 |
-
outputs=export_status
|
| 154 |
-
)
|
| 155 |
-
|
| 156 |
-
# Template Manager Tab
|
| 157 |
-
with gr.TabItem("Template Manager", id="template_tab"):
|
| 158 |
-
gr.Markdown("## Create and Manage Content Templates")
|
| 159 |
-
|
| 160 |
-
with gr.Row():
|
| 161 |
-
with gr.Column(scale=1):
|
| 162 |
-
template_name_input = gr.Textbox(
|
| 163 |
-
label="Template Name",
|
| 164 |
-
placeholder="e.g., baking, vegan, desserts",
|
| 165 |
-
lines=1
|
| 166 |
-
)
|
| 167 |
-
|
| 168 |
-
template_selector = gr.Dropdown(
|
| 169 |
-
choices=list(TEMPLATES.keys()),
|
| 170 |
-
label="Load Existing Template",
|
| 171 |
-
info="Select a template to view or edit"
|
| 172 |
-
)
|
| 173 |
-
|
| 174 |
-
with gr.Column(scale=2):
|
| 175 |
-
template_content = gr.Textbox(
|
| 176 |
-
labelimport gradio as gr
|
| 177 |
import google.generativeai as genai
|
| 178 |
import os
|
| 179 |
from dotenv import load_dotenv
|
|
|
|
| 1 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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