ahmedumeraziz commited on
Commit
f0b691d
·
verified ·
1 Parent(s): 0b166b4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from bs4 import BeautifulSoup
3
+ import gradio as gr
4
+
5
+ def check_seo(url):
6
+ try:
7
+ response = requests.get(url, timeout=10)
8
+ response.raise_for_status()
9
+ except Exception as e:
10
+ return f"❌ Error accessing URL: {str(e)}", ""
11
+
12
+ soup = BeautifulSoup(response.text, "html.parser")
13
+ report = []
14
+ fix_guide = []
15
+
16
+ # Title tag
17
+ title = soup.title.string if soup.title else None
18
+ if not title:
19
+ report.append("❌ Missing <title> tag.")
20
+ fix_guide.append("Add a descriptive <title> tag with relevant keywords.")
21
+ elif len(title) < 10 or len(title) > 70:
22
+ report.append("⚠️ <title> tag length is not optimal.")
23
+ fix_guide.append("Keep your title between 50-60 characters.")
24
+
25
+ # Meta description
26
+ meta_desc = soup.find("meta", attrs={"name": "description"})
27
+ if not meta_desc or not meta_desc.get("content"):
28
+ report.append("❌ Missing meta description.")
29
+ fix_guide.append("Add a <meta name='description'> with a summary of your page.")
30
+ elif len(meta_desc["content"]) < 50 or len(meta_desc["content"]) > 160:
31
+ report.append("⚠️ Meta description length is not optimal.")
32
+ fix_guide.append("Keep meta descriptions between 150-160 characters.")
33
+
34
+ # Headings
35
+ h1_tags = soup.find_all("h1")
36
+ if len(h1_tags) != 1:
37
+ report.append(f"⚠️ Found {len(h1_tags)} <h1> tags.")
38
+ fix_guide.append("Use exactly one <h1> tag to define the main heading.")
39
+
40
+ # Images with alt
41
+ images = soup.find_all("img")
42
+ missing_alt = [img for img in images if not img.get("alt")]
43
+ if missing_alt:
44
+ report.append(f"⚠️ {len(missing_alt)} image(s) missing alt attribute.")
45
+ fix_guide.append("Add descriptive alt text to all images.")
46
+
47
+ # Mobile-friendliness & Page speed (basic hints, real check would require APIs)
48
+ report.append("ℹ️ For mobile-friendliness and performance, use tools like Google PageSpeed Insights.")
49
+ fix_guide.append("Use https://pagespeed.web.dev/ for full performance and mobile checks.")
50
+
51
+ return "\n".join(report), "\n".join(fix_guide)
52
+
53
+ gr.Interface(
54
+ fn=check_seo,
55
+ inputs=gr.Textbox(label="Enter Website URL"),
56
+ outputs=[gr.Textbox(label="SEO Report"), gr.Textbox(label="Fix Suggestions")],
57
+ title="Website SEO Check",
58
+ description="Checks basic SEO elements of a given URL and provides recommendations."
59
+ ).launch()