SEOlytics-AI / app.py
KeyarSrini's picture
Update app.py
c3c1bed verified
Raw History Blame Contribute Delete
1.38 kB
import gradio as gr
import openai
import os
# Set your OpenAI key (use HF secrets)
client = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
def seo_audit(url):
if not url:
return "Please enter a valid URL."
prompt = f"""
You are SEOlytics AI, a world-class SEO Analyst.
Audit this URL as if it's a live site: {url}
Break your analysis into these parts:
1. Basic Info (Title, Meta, OG tags)
2. Technical SEO (Speed, HTTPS, Schema, Robots.txt)
3. On-Page SEO (Headings, Keywords, Alt Tags)
4. Content Quality (Readability, Word Count, Keyword Density)
5. UX and Performance (Mobile-friendliness, CTA, Accessibility)
6. SEO Score (0–100)
7. Top 5 Priority Recommendations
"""
try:
response = client.chat.completions.create(
model="gpt-4",
messages=[
{"role": "system", "content": "You are an expert SEO analyst."},
{"role": "user", "content": prompt}
]
)
return response.choices[0].message.content
except Exception as e:
return f"Error: {str(e)}"
demo = gr.Interface(
fn=seo_audit,
inputs=gr.Textbox(label="Enter Website URL"),
outputs=gr.Textbox(label="SEO Audit Report", lines=25),
title="SEOlytics AI",
description="AI-Powered SEO Analyzer – Just paste a URL and get insights!"
)
if __name__ == "__main__":
demo.launch()