Spaces:
Runtime error
Runtime error
Upload 4 files
Browse files
README.md
CHANGED
|
@@ -1,12 +1,34 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: SemRush Domain Analyzer
|
| 3 |
+
emoji: 🔍
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.44.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
short_description: Analyze domain SEO metrics using SemRush API
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# SemRush Domain Analyzer
|
| 15 |
+
|
| 16 |
+
A Gradio app that analyzes domain SEO metrics using the SemRush API.
|
| 17 |
+
|
| 18 |
+
## Features
|
| 19 |
+
|
| 20 |
+
- Domain overview with organic traffic trends (last 2 years)
|
| 21 |
+
- Organic summary across different databases
|
| 22 |
+
- Backlinks summary analysis
|
| 23 |
+
|
| 24 |
+
## Setup
|
| 25 |
+
|
| 26 |
+
1. Set your SemRush credentials in Hugging Face Secrets:
|
| 27 |
+
- `SEMRUSH_USER_ID`: Your SemRush user ID
|
| 28 |
+
- `SEMRUSH_API_KEY`: Your SemRush API key
|
| 29 |
+
|
| 30 |
+
2. The app will automatically use these credentials to fetch data
|
| 31 |
+
|
| 32 |
+
## Usage
|
| 33 |
+
|
| 34 |
+
Simply enter a domain name (with or without protocol) and click "Analyze Domain" to get comprehensive SEO data.
|
app.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
from parser import SemRush
|
| 4 |
+
import json
|
| 5 |
+
|
| 6 |
+
# Get credentials from Hugging Face Secrets
|
| 7 |
+
SEMRUSH_USER_ID = os.getenv("SEMRUSH_USER_ID")
|
| 8 |
+
SEMRUSH_API_KEY = os.getenv("SEMRUSH_API_KEY")
|
| 9 |
+
|
| 10 |
+
def get_domain_overview(domain):
|
| 11 |
+
"""Get domain overview data from SemRush."""
|
| 12 |
+
try:
|
| 13 |
+
semrush = SemRush(SEMRUSH_USER_ID, SEMRUSH_API_KEY, domain)
|
| 14 |
+
overview = semrush.domainOverview()
|
| 15 |
+
|
| 16 |
+
if "error" in overview:
|
| 17 |
+
return f"Error: {overview['error']}"
|
| 18 |
+
|
| 19 |
+
# Format the data for display
|
| 20 |
+
formatted_data = []
|
| 21 |
+
for date, traffic in overview.items():
|
| 22 |
+
formatted_data.append(f"Date: {date}, Organic Traffic: {traffic}")
|
| 23 |
+
|
| 24 |
+
return "\n".join(formatted_data) if formatted_data else "No data found"
|
| 25 |
+
|
| 26 |
+
except Exception as e:
|
| 27 |
+
return f"Error: {str(e)}"
|
| 28 |
+
|
| 29 |
+
def get_organic_summary(domain):
|
| 30 |
+
"""Get organic summary data from SemRush."""
|
| 31 |
+
try:
|
| 32 |
+
semrush = SemRush(SEMRUSH_USER_ID, SEMRUSH_API_KEY, domain)
|
| 33 |
+
summary = semrush.organicSummary()
|
| 34 |
+
|
| 35 |
+
if "error" in summary:
|
| 36 |
+
return f"Error: {summary['error']}"
|
| 37 |
+
|
| 38 |
+
# Format the data for display
|
| 39 |
+
formatted_data = []
|
| 40 |
+
for database, traffic in summary.items():
|
| 41 |
+
formatted_data.append(f"Database: {database}, Organic Traffic: {traffic}")
|
| 42 |
+
|
| 43 |
+
return "\n".join(formatted_data) if formatted_data else "No data found"
|
| 44 |
+
|
| 45 |
+
except Exception as e:
|
| 46 |
+
return f"Error: {str(e)}"
|
| 47 |
+
|
| 48 |
+
def get_backlinks_summary(domain):
|
| 49 |
+
"""Get backlinks summary data from SemRush."""
|
| 50 |
+
try:
|
| 51 |
+
semrush = SemRush(SEMRUSH_USER_ID, SEMRUSH_API_KEY, domain)
|
| 52 |
+
backlinks = semrush.backlinksSummary()
|
| 53 |
+
|
| 54 |
+
if "error" in backlinks:
|
| 55 |
+
return f"Error: {backlinks['error']}"
|
| 56 |
+
|
| 57 |
+
# Format the data for display
|
| 58 |
+
return json.dumps(backlinks, indent=2)
|
| 59 |
+
|
| 60 |
+
except Exception as e:
|
| 61 |
+
return f"Error: {str(e)}"
|
| 62 |
+
|
| 63 |
+
def get_all_data(domain):
|
| 64 |
+
"""Get all available data for a domain."""
|
| 65 |
+
if not domain:
|
| 66 |
+
return "Please enter a domain name"
|
| 67 |
+
|
| 68 |
+
results = {}
|
| 69 |
+
|
| 70 |
+
# Clean domain (remove protocol if present)
|
| 71 |
+
clean_domain = domain.replace('https://', '').replace('http://', '').strip('/')
|
| 72 |
+
|
| 73 |
+
# Get all data types
|
| 74 |
+
results["Domain Overview"] = get_domain_overview(clean_domain)
|
| 75 |
+
results["Organic Summary"] = get_organic_summary(clean_domain)
|
| 76 |
+
results["Backlinks Summary"] = get_backlinks_summary(clean_domain)
|
| 77 |
+
|
| 78 |
+
# Format output
|
| 79 |
+
output = f"# SemRush Data for: {clean_domain}\n\n"
|
| 80 |
+
|
| 81 |
+
for section, data in results.items():
|
| 82 |
+
output += f"## {section}\n{data}\n\n"
|
| 83 |
+
|
| 84 |
+
return output
|
| 85 |
+
|
| 86 |
+
# Create Gradio interface
|
| 87 |
+
with gr.Blocks(title="SemRush Domain Analyzer") as demo:
|
| 88 |
+
gr.Markdown("# SemRush Domain Analyzer")
|
| 89 |
+
gr.Markdown("Enter a domain name to get SEO data from SemRush API")
|
| 90 |
+
|
| 91 |
+
with gr.Row():
|
| 92 |
+
domain_input = gr.Textbox(
|
| 93 |
+
label="Domain Name",
|
| 94 |
+
placeholder="example.com or https://example.com",
|
| 95 |
+
value=""
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
with gr.Row():
|
| 99 |
+
analyze_btn = gr.Button("Analyze Domain", variant="primary")
|
| 100 |
+
|
| 101 |
+
with gr.Row():
|
| 102 |
+
output = gr.Textbox(
|
| 103 |
+
label="Results",
|
| 104 |
+
lines=20,
|
| 105 |
+
max_lines=50,
|
| 106 |
+
show_copy_button=True
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
analyze_btn.click(
|
| 110 |
+
fn=get_all_data,
|
| 111 |
+
inputs=domain_input,
|
| 112 |
+
outputs=output
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
# Add examples
|
| 116 |
+
gr.Examples(
|
| 117 |
+
examples=[
|
| 118 |
+
["example.com"],
|
| 119 |
+
["google.com"],
|
| 120 |
+
["github.com"]
|
| 121 |
+
],
|
| 122 |
+
inputs=domain_input
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
if __name__ == "__main__":
|
| 126 |
+
demo.launch()
|
logger.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import logging
|
| 3 |
+
|
| 4 |
+
def setup_logging():
|
| 5 |
+
logging.basicConfig(level=logging.INFO)
|
| 6 |
+
return logging.getLogger(__name__)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
requests
|
| 3 |
+
fake_headers
|