Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
from bs4 import BeautifulSoup
|
| 4 |
+
import google.generativeai as genai
|
| 5 |
+
|
| 6 |
+
# -----------------------------
|
| 7 |
+
# Helper: Fetch & clean webpage
|
| 8 |
+
# -----------------------------
|
| 9 |
+
def fetch_website_text(url):
|
| 10 |
+
headers = {"User-Agent": "Mozilla/5.0"}
|
| 11 |
+
response = requests.get(url, headers=headers, timeout=10)
|
| 12 |
+
response.raise_for_status()
|
| 13 |
+
|
| 14 |
+
soup = BeautifulSoup(response.text, "html.parser")
|
| 15 |
+
|
| 16 |
+
# Remove scripts & styles
|
| 17 |
+
for tag in soup(["script", "style", "noscript"]):
|
| 18 |
+
tag.decompose()
|
| 19 |
+
|
| 20 |
+
title = soup.title.string if soup.title else ""
|
| 21 |
+
h1 = soup.find("h1").get_text(strip=True) if soup.find("h1") else ""
|
| 22 |
+
|
| 23 |
+
body_text = " ".join(soup.stripped_strings)
|
| 24 |
+
body_text = body_text[:8000] # keep token usage sane
|
| 25 |
+
|
| 26 |
+
return f"""
|
| 27 |
+
PAGE TITLE:
|
| 28 |
+
{title}
|
| 29 |
+
|
| 30 |
+
PRIMARY H1:
|
| 31 |
+
{h1}
|
| 32 |
+
|
| 33 |
+
VISIBLE CONTENT:
|
| 34 |
+
{body_text}
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
# -----------------------------
|
| 38 |
+
# Gemini analysis
|
| 39 |
+
# -----------------------------
|
| 40 |
+
def analyze_website(api_key, url, industry, goal):
|
| 41 |
+
if not api_key:
|
| 42 |
+
return "β Please enter your Gemini API key."
|
| 43 |
+
|
| 44 |
+
try:
|
| 45 |
+
genai.configure(api_key=api_key)
|
| 46 |
+
|
| 47 |
+
website_text = fetch_website_text(url)
|
| 48 |
+
|
| 49 |
+
prompt = f"""
|
| 50 |
+
You are an AI consultant helping small businesses improve their websites.
|
| 51 |
+
|
| 52 |
+
Business context:
|
| 53 |
+
- Industry: {industry}
|
| 54 |
+
- Primary goal: {goal}
|
| 55 |
+
|
| 56 |
+
Analyze the website content below and provide recommendations in this structure:
|
| 57 |
+
|
| 58 |
+
1. Messaging Clarity (score 1β10)
|
| 59 |
+
- Main issue
|
| 60 |
+
- 2β3 actionable recommendations
|
| 61 |
+
|
| 62 |
+
2. Conversion Effectiveness (score 1β10)
|
| 63 |
+
- Main issue
|
| 64 |
+
- 2β3 actionable recommendations
|
| 65 |
+
|
| 66 |
+
3. Trust & Credibility (score 1β10)
|
| 67 |
+
- Main issue
|
| 68 |
+
- 2β3 actionable recommendations
|
| 69 |
+
|
| 70 |
+
4. User Experience Issues
|
| 71 |
+
- Bullet list of issues
|
| 72 |
+
|
| 73 |
+
5. AI & Automation Opportunities
|
| 74 |
+
- 3 concrete ideas a small business could implement
|
| 75 |
+
|
| 76 |
+
End with:
|
| 77 |
+
- Overall score out of 100
|
| 78 |
+
- Top 3 fixes to prioritize this week
|
| 79 |
+
|
| 80 |
+
Use clear, non-technical business language.
|
| 81 |
+
|
| 82 |
+
Website content:
|
| 83 |
+
{website_text}
|
| 84 |
+
"""
|
| 85 |
+
|
| 86 |
+
model = genai.GenerativeModel("gemini-1.5-pro")
|
| 87 |
+
response = model.generate_content(prompt)
|
| 88 |
+
|
| 89 |
+
return response.text
|
| 90 |
+
|
| 91 |
+
except Exception as e:
|
| 92 |
+
return f"β Error: {str(e)}"
|
| 93 |
+
|
| 94 |
+
# -----------------------------
|
| 95 |
+
# Gradio UI
|
| 96 |
+
# -----------------------------
|
| 97 |
+
with gr.Blocks(title="AI Website Review Tool") as demo:
|
| 98 |
+
gr.Markdown("## π AI Website Review Tool")
|
| 99 |
+
gr.Markdown("Analyze a website and receive practical, business-focused recommendations.")
|
| 100 |
+
|
| 101 |
+
with gr.Row():
|
| 102 |
+
api_key = gr.Textbox(
|
| 103 |
+
label="Gemini API Key",
|
| 104 |
+
placeholder="Paste your Gemini API key here",
|
| 105 |
+
type="password"
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
url = gr.Textbox(
|
| 109 |
+
label="Website URL",
|
| 110 |
+
placeholder="https://example.com"
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
industry = gr.Dropdown(
|
| 114 |
+
label="Industry",
|
| 115 |
+
choices=["General SMB", "Law Firm", "Hospitality", "Healthcare", "Real Estate"],
|
| 116 |
+
value="General SMB"
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
goal = gr.Dropdown(
|
| 120 |
+
label="Primary Website Goal",
|
| 121 |
+
choices=["Generate leads", "Sell services", "Build credibility", "Educate visitors"],
|
| 122 |
+
value="Generate leads"
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
analyze_btn = gr.Button("Analyze Website")
|
| 126 |
+
|
| 127 |
+
output = gr.Markdown(label="Analysis Results")
|
| 128 |
+
|
| 129 |
+
analyze_btn.click(
|
| 130 |
+
fn=analyze_website,
|
| 131 |
+
inputs=[api_key, url, industry, goal],
|
| 132 |
+
outputs=output
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
demo.launch()
|