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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import openai
|
3 |
+
import anthropic
|
4 |
+
import json
|
5 |
+
import os
|
6 |
+
from typing import Dict, Any
|
7 |
+
|
8 |
+
class SEOAgent:
|
9 |
+
def __init__(self):
|
10 |
+
self.seo_tasks = {
|
11 |
+
"Keyword Research & Analysis": {
|
12 |
+
"description": "Research short-tail and long-tail keywords with competition analysis",
|
13 |
+
"prompt": """You are an expert SEO strategist with 15 years of experience. Your task is to conduct thorough keyword research.
|
14 |
+
|
15 |
+
CONTEXT: You must think in first principles - understanding user intent, search behaviour, and market dynamics.
|
16 |
+
|
17 |
+
TASK: Analyse the provided topic/industry and deliver actionable keyword insights.
|
18 |
+
|
19 |
+
METHODOLOGY:
|
20 |
+
1. Identify 10-15 high-value short-tail keywords (1-2 words)
|
21 |
+
2. Generate 20-30 long-tail keywords (3+ words) with commercial intent
|
22 |
+
3. Categorise keywords by search intent (informational, navigational, commercial, transactional)
|
23 |
+
4. Estimate search volumes and competition levels
|
24 |
+
5. Identify keyword gaps competitors might be missing
|
25 |
+
|
26 |
+
OUTPUT FORMAT:
|
27 |
+
- Primary Keywords (short-tail)
|
28 |
+
- Long-tail Opportunities
|
29 |
+
- Intent Classification
|
30 |
+
- Competition Analysis
|
31 |
+
- Content Gap Opportunities
|
32 |
+
- Recommended Focus Keywords (top 5 with rationale)
|
33 |
+
|
34 |
+
CONSTRAINTS:
|
35 |
+
- Use British English
|
36 |
+
- Be direct and actionable
|
37 |
+
- Consider second-order effects (how these keywords impact overall strategy)
|
38 |
+
- Think about third-order consequences (long-term brand positioning)
|
39 |
+
|
40 |
+
Industry/Topic: {user_input}"""
|
41 |
+
},
|
42 |
+
|
43 |
+
"Technical SEO Audit": {
|
44 |
+
"description": "Detailed technical analysis and recommendations",
|
45 |
+
"prompt": """You are a technical SEO specialist with deep expertise in website architecture and search engine mechanics.
|
46 |
+
|
47 |
+
FIRST PRINCIPLES THINKING: Search engines need to crawl, understand, and index content efficiently.
|
48 |
+
|
49 |
+
TASK: Conduct a thorough technical SEO analysis for the provided website.
|
50 |
+
|
51 |
+
AUDIT FRAMEWORK:
|
52 |
+
1. Site Architecture Assessment
|
53 |
+
- URL structure evaluation
|
54 |
+
- Internal linking analysis
|
55 |
+
- Navigation hierarchy review
|
56 |
+
|
57 |
+
2. Technical Performance
|
58 |
+
- Page speed factors
|
59 |
+
- Core Web Vitals considerations
|
60 |
+
- Mobile responsiveness issues
|
61 |
+
|
62 |
+
3. Indexation Analysis
|
63 |
+
- Crawl accessibility
|
64 |
+
- XML sitemap structure
|
65 |
+
- Robots.txt configuration
|
66 |
+
|
67 |
+
4. On-page Technical Elements
|
68 |
+
- Meta tag optimisation
|
69 |
+
- Schema markup opportunities
|
70 |
+
- Header tag hierarchy
|
71 |
+
|
72 |
+
SECOND-ORDER CONSIDERATIONS:
|
73 |
+
- How technical issues impact user experience
|
74 |
+
- Effect on conversion rates and business metrics
|
75 |
+
|
76 |
+
THIRD-ORDER CONSEQUENCES:
|
77 |
+
- Long-term search visibility implications
|
78 |
+
- Brand credibility and trust factors
|
79 |
+
|
80 |
+
OUTPUT STRUCTURE:
|
81 |
+
- Critical Issues (immediate fixes required)
|
82 |
+
- Moderate Priority Items
|
83 |
+
- Enhancement Opportunities
|
84 |
+
- Implementation Roadmap (30/60/90 days)
|
85 |
+
|
86 |
+
Website URL: {user_input}"""
|
87 |
+
},
|
88 |
+
|
89 |
+
"Content Strategy Development": {
|
90 |
+
"description": "Create a detailed content strategies aligned with SEO goals",
|
91 |
+
"prompt": """You are a content strategist who understands the intersection of user needs, search behaviour, and business objectives.
|
92 |
+
|
93 |
+
FIRST PRINCIPLES: Content must solve user problems whilst achieving business goals through search visibility.
|
94 |
+
|
95 |
+
OBJECTIVE: Develop a detailed content strategy for the specified industry/niche.
|
96 |
+
|
97 |
+
STRATEGIC FRAMEWORK:
|
98 |
+
1. Audience Analysis
|
99 |
+
- Primary and secondary personas
|
100 |
+
- Content consumption patterns
|
101 |
+
- Pain points and information needs
|
102 |
+
|
103 |
+
2. Content Pillars
|
104 |
+
- Core topic areas
|
105 |
+
- Supporting subtopics
|
106 |
+
- Content cluster strategy
|
107 |
+
|
108 |
+
3. Content Types & Formats
|
109 |
+
- Blog posts, guides, resources
|
110 |
+
- Video, infographic, interactive content
|
111 |
+
- Gated vs. ungated content strategy
|
112 |
+
|
113 |
+
4. Editorial Calendar Planning
|
114 |
+
- Publishing frequency recommendations
|
115 |
+
- Seasonal content opportunities
|
116 |
+
- Evergreen vs. trending content balance
|
117 |
+
|
118 |
+
SECOND-ORDER EFFECTS:
|
119 |
+
- How content supports different funnel stages
|
120 |
+
- Cross-promotional opportunities
|
121 |
+
- Social media amplification potential
|
122 |
+
|
123 |
+
THIRD-ORDER IMPLICATIONS:
|
124 |
+
- Brand authority building
|
125 |
+
- Industry thought leadership positioning
|
126 |
+
- Long-term organic traffic growth
|
127 |
+
|
128 |
+
DELIVERABLES:
|
129 |
+
- Content Pillar Framework
|
130 |
+
- 30 Content Ideas with SEO Focus
|
131 |
+
- Editorial Calendar Template
|
132 |
+
- Content Performance KPIs
|
133 |
+
- Resource Requirements
|
134 |
+
|
135 |
+
Industry/Business Focus: {user_input}"""
|
136 |
+
},
|
137 |
+
|
138 |
+
"Competitor SEO Analysis": {
|
139 |
+
"description": "Analyse competitor strategies and identify opportunities",
|
140 |
+
"prompt": """You are a competitive intelligence analyst specialising in SEO strategy evaluation.
|
141 |
+
|
142 |
+
ANALYTICAL APPROACH: Reverse-engineer successful competitor strategies whilst identifying market gaps.
|
143 |
+
|
144 |
+
MISSION: Conduct a detailed competitor analysis to uncover strategic opportunities.
|
145 |
+
|
146 |
+
ANALYSIS FRAMEWORK:
|
147 |
+
1. Competitor Identification
|
148 |
+
- Direct competitors
|
149 |
+
- Indirect/industry competitors
|
150 |
+
- Aspirational competitors (different sectors, similar strategies)
|
151 |
+
|
152 |
+
2. Content Strategy Analysis
|
153 |
+
- Top-performing content types
|
154 |
+
- Content gap identification
|
155 |
+
- Publishing patterns and frequency
|
156 |
+
|
157 |
+
3. Keyword Strategy Evaluation
|
158 |
+
- Keyword overlap analysis
|
159 |
+
- Competitor-unique keywords
|
160 |
+
- Ranking position comparisons
|
161 |
+
|
162 |
+
4. Technical Strategy Assessment
|
163 |
+
- Site architecture approaches
|
164 |
+
- User experience patterns
|
165 |
+
- Technical advantages/disadvantages
|
166 |
+
|
167 |
+
5. Link Building Strategy Review
|
168 |
+
- Backlink profile analysis
|
169 |
+
- Link acquisition patterns
|
170 |
+
- Authority building approaches
|
171 |
+
|
172 |
+
SECOND-ORDER CONSIDERATIONS:
|
173 |
+
- Market positioning implications
|
174 |
+
- Resource allocation insights
|
175 |
+
- Timing and opportunity windows
|
176 |
+
|
177 |
+
THIRD-ORDER STRATEGY:
|
178 |
+
- Long-term competitive differentiation
|
179 |
+
- Market leadership positioning
|
180 |
+
- Industry disruption opportunities
|
181 |
+
|
182 |
+
OUTPUT STRUCTURE:
|
183 |
+
- Competitor Landscape Overview
|
184 |
+
- Strategic Strengths & Weaknesses
|
185 |
+
- Opportunity Matrix
|
186 |
+
- Recommended Actions (immediate, short-term, long-term)
|
187 |
+
- Competitive Differentiation Strategy
|
188 |
+
|
189 |
+
Competitor Domain(s) or Industry: {user_input}"""
|
190 |
+
},
|
191 |
+
|
192 |
+
"Link Building Strategy": {
|
193 |
+
"description": "Develop detailed link acquisition strategies",
|
194 |
+
"prompt": """You are a digital PR and link building expert with proven success in building high-authority backlink profiles.
|
195 |
+
|
196 |
+
CORE PRINCIPLE: Quality links come from creating genuine value and building authentic relationships.
|
197 |
+
|
198 |
+
OBJECTIVE: Design a detailed link building strategy for the specified website/industry.
|
199 |
+
|
200 |
+
STRATEGIC APPROACH:
|
201 |
+
1. Link Opportunity Audit
|
202 |
+
- Industry-relevant websites
|
203 |
+
- Competitor backlink analysis
|
204 |
+
- Broken link opportunities
|
205 |
+
- Resource page inclusions
|
206 |
+
|
207 |
+
2. Content-Led Link Building
|
208 |
+
- Linkable asset creation
|
209 |
+
- Digital PR campaign ideas
|
210 |
+
- Industry research and surveys
|
211 |
+
- Expert roundup opportunities
|
212 |
+
|
213 |
+
3. Relationship Building Framework
|
214 |
+
- Industry influencer identification
|
215 |
+
- Partnership opportunities
|
216 |
+
- Guest posting prospects
|
217 |
+
- Podcast appearance possibilities
|
218 |
+
|
219 |
+
4. Technical Link Strategies
|
220 |
+
- Internal linking optimisation
|
221 |
+
- Link reclamation opportunities
|
222 |
+
- Brand mention conversion
|
223 |
+
- Competitor link replication
|
224 |
+
|
225 |
+
SECOND-ORDER EFFECTS:
|
226 |
+
- Brand awareness and visibility
|
227 |
+
- Referral traffic generation
|
228 |
+
- Industry relationship development
|
229 |
+
|
230 |
+
THIRD-ORDER BENEFITS:
|
231 |
+
- Market authority establishment
|
232 |
+
- Long-term partnership development
|
233 |
+
- Crisis communication network
|
234 |
+
|
235 |
+
DELIVERABLES:
|
236 |
+
- Target Website List (50+ prospects)
|
237 |
+
- Outreach Email Templates
|
238 |
+
- Content Campaign Ideas
|
239 |
+
- Monthly Link Building Calendar
|
240 |
+
- Success Metrics and KPIs
|
241 |
+
|
242 |
+
Website/Industry: {user_input}"""
|
243 |
+
},
|
244 |
+
|
245 |
+
"Local SEO Optimisation": {
|
246 |
+
"description": "Optimise for local search visibility and conversions",
|
247 |
+
"prompt": """You are a local SEO specialist who understands how local businesses win in their geographic markets.
|
248 |
+
|
249 |
+
FUNDAMENTAL TRUTH: Local search success requires consistent NAP data, authentic reviews, and genuine community engagement.
|
250 |
+
|
251 |
+
TASK: Create a detailed local SEO strategy for the specified business.
|
252 |
+
|
253 |
+
OPTIMISATION FRAMEWORK:
|
254 |
+
1. Google Business Profile Excellence
|
255 |
+
- Profile completion and optimisation
|
256 |
+
- Category selection strategy
|
257 |
+
- Photo and video content plan
|
258 |
+
- Regular posting schedule
|
259 |
+
|
260 |
+
2. Local Citation Building
|
261 |
+
- Core citation sources identification
|
262 |
+
- Industry-specific directories
|
263 |
+
- NAP consistency audit
|
264 |
+
- Citation cleanup requirements
|
265 |
+
|
266 |
+
3. Review Management Strategy
|
267 |
+
- Review acquisition campaigns
|
268 |
+
- Response strategy for all reviews
|
269 |
+
- Reputation monitoring system
|
270 |
+
- Customer feedback integration
|
271 |
+
|
272 |
+
4. Local Content Strategy
|
273 |
+
- Location-specific content creation
|
274 |
+
- Community event participation
|
275 |
+
- Local partnership opportunities
|
276 |
+
- Geo-targeted keyword integration
|
277 |
+
|
278 |
+
5. Technical Local SEO
|
279 |
+
- Schema markup implementation
|
280 |
+
- Location page optimisation
|
281 |
+
- Mobile-first considerations
|
282 |
+
- Local link building
|
283 |
+
|
284 |
+
SECOND-ORDER IMPACT:
|
285 |
+
- Customer trust and credibility
|
286 |
+
- Foot traffic and phone call increases
|
287 |
+
- Local market dominance
|
288 |
+
|
289 |
+
LONG-TERM VISION:
|
290 |
+
- Community brand recognition
|
291 |
+
- Market leadership position
|
292 |
+
- Sustainable competitive advantage
|
293 |
+
|
294 |
+
OUTPUT:
|
295 |
+
- Local SEO Audit Results
|
296 |
+
- Google Business Profile Action Plan
|
297 |
+
- Citation Building Strategy
|
298 |
+
- Review Management System
|
299 |
+
- Local Content Calendar
|
300 |
+
|
301 |
+
Business Name/Location: {user_input}"""
|
302 |
+
},
|
303 |
+
|
304 |
+
"Performance Analysis & Reporting": {
|
305 |
+
"description": "Analyse SEO performance and create actionable insights",
|
306 |
+
"prompt": """You are a data analyst who transforms SEO metrics into business intelligence and strategic recommendations.
|
307 |
+
|
308 |
+
DATA PHILOSOPHY: Numbers tell stories, but insights drive decisions and business growth.
|
309 |
+
|
310 |
+
OBJECTIVE: Analyse SEO performance data and provide actionable strategic recommendations.
|
311 |
+
|
312 |
+
ANALYSIS FRAMEWORK:
|
313 |
+
1. Traffic & Ranking Analysis
|
314 |
+
- Organic traffic trends
|
315 |
+
- Keyword ranking movements
|
316 |
+
- Click-through rate analysis
|
317 |
+
- Impression and position data
|
318 |
+
|
319 |
+
2. Conversion & Business Impact
|
320 |
+
- Goal completion analysis
|
321 |
+
- Revenue attribution to organic search
|
322 |
+
- Lead quality assessment
|
323 |
+
- Customer lifetime value correlation
|
324 |
+
|
325 |
+
3. Technical Performance Review
|
326 |
+
- Site speed impact on rankings
|
327 |
+
- Core Web Vitals performance
|
328 |
+
- Mobile usability metrics
|
329 |
+
- Crawl error identification
|
330 |
+
|
331 |
+
4. Content Performance Evaluation
|
332 |
+
- Top-performing content identification
|
333 |
+
- Content gap analysis
|
334 |
+
- User engagement metrics
|
335 |
+
- Social sharing patterns
|
336 |
+
|
337 |
+
SECOND-ORDER INSIGHTS:
|
338 |
+
- User behaviour pattern recognition
|
339 |
+
- Seasonal trend identification
|
340 |
+
- Competitive position changes
|
341 |
+
|
342 |
+
STRATEGIC IMPLICATIONS:
|
343 |
+
- Resource allocation recommendations
|
344 |
+
- Priority setting for improvements
|
345 |
+
- ROI optimisation opportunities
|
346 |
+
|
347 |
+
REPORTING STRUCTURE:
|
348 |
+
- Executive Summary (key wins and challenges)
|
349 |
+
- Performance Metrics Dashboard
|
350 |
+
- Trend Analysis and Insights
|
351 |
+
- Recommended Actions with Timeline
|
352 |
+
- Projected Impact Assessment
|
353 |
+
|
354 |
+
Website/Data Period: {user_input}"""
|
355 |
+
},
|
356 |
+
|
357 |
+
"Site Architecture Planning": {
|
358 |
+
"description": "Design optimal website structure for SEO and user experience",
|
359 |
+
"prompt": """You are a website architect who designs structures that serve both users and search engines effectively.
|
360 |
+
|
361 |
+
ARCHITECTURAL PRINCIPLE: Great site structure makes information findable, understandable, and actionable.
|
362 |
+
|
363 |
+
CHALLENGE: Design optimal website architecture for the specified project requirements.
|
364 |
+
|
365 |
+
PLANNING FRAMEWORK:
|
366 |
+
1. Information Architecture Design
|
367 |
+
- Content categorisation and hierarchy
|
368 |
+
- User journey mapping
|
369 |
+
- Navigation structure planning
|
370 |
+
- URL structure strategy
|
371 |
+
|
372 |
+
2. SEO-Friendly Architecture
|
373 |
+
- Internal linking strategy
|
374 |
+
- Category and tag organisation
|
375 |
+
- Breadcrumb navigation planning
|
376 |
+
- XML sitemap structure
|
377 |
+
|
378 |
+
3. User Experience Integration
|
379 |
+
- Mobile-first design considerations
|
380 |
+
- Page load speed optimisation
|
381 |
+
- Conversion path optimisation
|
382 |
+
- Accessibility compliance
|
383 |
+
|
384 |
+
4. Technical Implementation
|
385 |
+
- CMS structure recommendations
|
386 |
+
- Database architecture considerations
|
387 |
+
- Caching strategy integration
|
388 |
+
- CDN implementation planning
|
389 |
+
|
390 |
+
SECOND-ORDER CONSIDERATIONS:
|
391 |
+
- Content scalability requirements
|
392 |
+
- Future expansion possibilities
|
393 |
+
- Integration with existing systems
|
394 |
+
|
395 |
+
LONG-TERM VISION:
|
396 |
+
- Sustainable growth accommodation
|
397 |
+
- Maintenance and update efficiency
|
398 |
+
- Competitive advantage creation
|
399 |
+
|
400 |
+
DELIVERABLES:
|
401 |
+
- Site Architecture Diagram
|
402 |
+
- URL Structure Guidelines
|
403 |
+
- Navigation Design Recommendations
|
404 |
+
- Internal Linking Strategy
|
405 |
+
- Technical Implementation Roadmap
|
406 |
+
|
407 |
+
Project Requirements: {user_input}"""
|
408 |
+
}
|
409 |
+
}
|
410 |
+
|
411 |
+
def call_openai(self, api_key: str, prompt: str, user_input: str) -> str:
|
412 |
+
try:
|
413 |
+
client = openai.OpenAI(api_key=api_key)
|
414 |
+
formatted_prompt = prompt.format(user_input=user_input)
|
415 |
+
|
416 |
+
response = client.chat.completions.create(
|
417 |
+
model="gpt-4o", # Latest GPT model
|
418 |
+
messages=[
|
419 |
+
{"role": "system", "content": "You are an expert SEO professional. Follow the prompt instructions precisely. Use British English, be direct and actionable, think in first principles, and consider second and third-order consequences."},
|
420 |
+
{"role": "user", "content": formatted_prompt}
|
421 |
+
],
|
422 |
+
max_tokens=2000,
|
423 |
+
temperature=0.7
|
424 |
+
)
|
425 |
+
|
426 |
+
return response.choices[0].message.content
|
427 |
+
|
428 |
+
except Exception as e:
|
429 |
+
return f"OpenAI API Error: {str(e)}"
|
430 |
+
|
431 |
+
def call_claude(self, api_key: str, prompt: str, user_input: str) -> str:
|
432 |
+
try:
|
433 |
+
client = anthropic.Anthropic(api_key=api_key)
|
434 |
+
formatted_prompt = prompt.format(user_input=user_input)
|
435 |
+
|
436 |
+
message = client.messages.create(
|
437 |
+
model="claude-3-5-sonnet-20241022", # Latest Claude model
|
438 |
+
max_tokens=2000,
|
439 |
+
temperature=0.7,
|
440 |
+
system="You are an expert SEO professional. Follow the prompt instructions precisely. Use British English, be direct and actionable, think in first principles, and consider second and third-order consequences.",
|
441 |
+
messages=[
|
442 |
+
{
|
443 |
+
"role": "user",
|
444 |
+
"content": formatted_prompt
|
445 |
+
}
|
446 |
+
]
|
447 |
+
)
|
448 |
+
|
449 |
+
return message.content[0].text
|
450 |
+
|
451 |
+
except Exception as e:
|
452 |
+
return f"Claude API Error: {str(e)}"
|
453 |
+
|
454 |
+
def create_interface():
|
455 |
+
seo_agent = SEOAgent()
|
456 |
+
|
457 |
+
def process_seo_task(openai_key, claude_key, selected_task, user_input, selected_model):
|
458 |
+
if not user_input.strip():
|
459 |
+
return "β **Error**: Please provide input for your SEO task."
|
460 |
+
|
461 |
+
if not openai_key.strip() and not claude_key.strip():
|
462 |
+
return "β **Error**: Please provide at least one API key (OpenAI or Claude)."
|
463 |
+
|
464 |
+
if selected_task not in seo_agent.seo_tasks:
|
465 |
+
return "β **Error**: Invalid task selection."
|
466 |
+
|
467 |
+
task_info = seo_agent.seo_tasks[selected_task]
|
468 |
+
prompt = task_info["prompt"]
|
469 |
+
|
470 |
+
# Format the output header
|
471 |
+
result = f"""# π SEO Agent Results
|
472 |
+
|
473 |
+
## Task: {selected_task}
|
474 |
+
**Model Used**: {selected_model}
|
475 |
+
**Input**: {user_input[:100]}{"..." if len(user_input) > 100 else ""}
|
476 |
+
|
477 |
+
---
|
478 |
+
|
479 |
+
"""
|
480 |
+
|
481 |
+
try:
|
482 |
+
if selected_model == "OpenAI GPT-4o" and openai_key.strip():
|
483 |
+
ai_response = seo_agent.call_openai(openai_key, prompt, user_input)
|
484 |
+
elif selected_model == "Claude 3.5 Sonnet" and claude_key.strip():
|
485 |
+
ai_response = seo_agent.call_claude(claude_key, prompt, user_input)
|
486 |
+
else:
|
487 |
+
return "β **Error**: Selected model requires corresponding API key."
|
488 |
+
|
489 |
+
result += ai_response
|
490 |
+
|
491 |
+
except Exception as e:
|
492 |
+
result += f"β **Processing Error**: {str(e)}"
|
493 |
+
|
494 |
+
return result
|
495 |
+
|
496 |
+
# Create Gradio interface
|
497 |
+
with gr.Blocks(
|
498 |
+
title="SEO Agent - Professional SEO Analysis Tool",
|
499 |
+
theme=gr.themes.Soft(),
|
500 |
+
css="""
|
501 |
+
.gradio-container {
|
502 |
+
max-width: 1200px !important;
|
503 |
+
}
|
504 |
+
.task-description {
|
505 |
+
background: #f8f9fa;
|
506 |
+
border-left: 4px solid #007bff;
|
507 |
+
padding: 15px;
|
508 |
+
margin: 10px 0;
|
509 |
+
border-radius: 5px;
|
510 |
+
}
|
511 |
+
"""
|
512 |
+
) as demo:
|
513 |
+
|
514 |
+
gr.Markdown("""
|
515 |
+
# π― SEO Agent - Professional SEO Analysis Tool
|
516 |
+
|
517 |
+
**Transform your SEO strategy with AI-powered insights**
|
518 |
+
|
519 |
+
This tool provides expert-level SEO analysis across eight core areas professional SEO executives handle daily. Each task uses carefully crafted prompts designed to produce optimal results.
|
520 |
+
|
521 |
+
---
|
522 |
+
""")
|
523 |
+
|
524 |
+
with gr.Row():
|
525 |
+
with gr.Column(scale=1):
|
526 |
+
gr.Markdown("## π API Configuration")
|
527 |
+
openai_key = gr.Textbox(
|
528 |
+
label="OpenAI API Key",
|
529 |
+
type="password",
|
530 |
+
placeholder="sk-proj-...",
|
531 |
+
info="Required for GPT-4o analysis"
|
532 |
+
)
|
533 |
+
claude_key = gr.Textbox(
|
534 |
+
label="Claude API Key",
|
535 |
+
type="password",
|
536 |
+
placeholder="sk-ant-...",
|
537 |
+
info="Required for Claude 3.5 Sonnet analysis"
|
538 |
+
)
|
539 |
+
|
540 |
+
selected_model = gr.Radio(
|
541 |
+
choices=["OpenAI GPT-4o", "Claude 3.5 Sonnet"],
|
542 |
+
label="Select AI Model",
|
543 |
+
value="OpenAI GPT-4o",
|
544 |
+
info="Choose your preferred AI model"
|
545 |
+
)
|
546 |
+
|
547 |
+
with gr.Column(scale=2):
|
548 |
+
gr.Markdown("## π SEO Task Selection")
|
549 |
+
|
550 |
+
task_choices = list(seo_agent.seo_tasks.keys())
|
551 |
+
selected_task = gr.Dropdown(
|
552 |
+
choices=task_choices,
|
553 |
+
label="Select SEO Task",
|
554 |
+
value=task_choices[0],
|
555 |
+
info="Choose the SEO analysis you need"
|
556 |
+
)
|
557 |
+
|
558 |
+
# Dynamic task description
|
559 |
+
task_description = gr.Markdown(
|
560 |
+
value=f"**{seo_agent.seo_tasks[task_choices[0]]['description']}**",
|
561 |
+
elem_classes=["task-description"]
|
562 |
+
)
|
563 |
+
|
564 |
+
def update_task_description(task):
|
565 |
+
return f"**{seo_agent.seo_tasks[task]['description']}**"
|
566 |
+
|
567 |
+
selected_task.change(
|
568 |
+
fn=update_task_description,
|
569 |
+
inputs=[selected_task],
|
570 |
+
outputs=[task_description]
|
571 |
+
)
|
572 |
+
|
573 |
+
with gr.Row():
|
574 |
+
with gr.Column():
|
575 |
+
user_input = gr.Textbox(
|
576 |
+
label="Your Input",
|
577 |
+
placeholder="Enter your website URL, industry, topic, or specific requirements...",
|
578 |
+
lines=4,
|
579 |
+
info="Provide relevant details for your selected SEO task"
|
580 |
+
)
|
581 |
+
|
582 |
+
analyze_btn = gr.Button(
|
583 |
+
"π Analyse",
|
584 |
+
variant="primary",
|
585 |
+
size="lg"
|
586 |
+
)
|
587 |
+
|
588 |
+
with gr.Row():
|
589 |
+
with gr.Column():
|
590 |
+
output = gr.Markdown(
|
591 |
+
label="SEO Analysis Results",
|
592 |
+
value="Results will appear here after analysis...",
|
593 |
+
height=600
|
594 |
+
)
|
595 |
+
|
596 |
+
# Button click handler
|
597 |
+
analyze_btn.click(
|
598 |
+
fn=process_seo_task,
|
599 |
+
inputs=[openai_key, claude_key, selected_task, user_input, selected_model],
|
600 |
+
outputs=[output]
|
601 |
+
)
|
602 |
+
|
603 |
+
gr.Markdown("""
|
604 |
+
---
|
605 |
+
|
606 |
+
## π― Available SEO Tasks
|
607 |
+
|
608 |
+
1. **Keyword Research & Analysis** - Detailed keyword strategy development
|
609 |
+
2. **Technical SEO Audit** - Complete technical analysis and recommendations
|
610 |
+
3. **Content Strategy Development** - Strategic content planning aligned with SEO goals
|
611 |
+
4. **Competitor SEO Analysis** - Competitive intelligence and opportunity identification
|
612 |
+
5. **Link Building Strategy** - Authority-building link acquisition strategies
|
613 |
+
6. **Local SEO Optimisation** - Local search visibility and conversion optimisation
|
614 |
+
7. **Performance Analysis & Reporting** - Data-driven insights and strategic recommendations
|
615 |
+
8. **Site Architecture Planning** - Optimal website structure for SEO and UX
|
616 |
+
|
617 |
+
**Note**: This tool requires either an OpenAI or Claude API key. Results are generated in real-time and formatted for immediate use in your SEO strategy.
|
618 |
+
""")
|
619 |
+
|
620 |
+
return demo
|
621 |
+
|
622 |
+
if __name__ == "__main__":
|
623 |
+
demo = create_interface()
|
624 |
+
demo.launch(
|
625 |
+
server_name="0.0.0.0",
|
626 |
+
server_port=7860,
|
627 |
+
share=True
|
628 |
+
)
|