Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import requests | |
| import json | |
| from bs4 import BeautifulSoup | |
| def validate_schema(url): | |
| try: | |
| response = requests.get(url, timeout=5) | |
| response.raise_for_status() | |
| soup = BeautifulSoup(response.text, 'html.parser') | |
| scripts = soup.find_all('script', type='application/ld+json') | |
| results = [] | |
| for script in scripts: | |
| try: | |
| data = json.loads(script.string) | |
| if isinstance(data, dict): | |
| results.append(data) | |
| elif isinstance(data, list): | |
| results.extend(data) | |
| except Exception as e: | |
| continue | |
| detected_types = list({item.get('@type', 'Unknown') for item in results if '@type' in item}) | |
| core_types = {'Organization', 'Article', 'Person'} | |
| trust_trail = any(t in core_types for t in detected_types) | |
| schema_health = round(len(detected_types) / max(len(scripts), 1), 2) | |
| return { | |
| "trustTrail": trust_trail, | |
| "schemaHealth": schema_health, | |
| "detectedTypes": detected_types, | |
| "warnings": [] if trust_trail else ["No core Trust Trail types (Organization, Article, Person) found."] | |
| } | |
| except Exception as e: | |
| return { | |
| "trustTrail": False, | |
| "schemaHealth": 0.0, | |
| "detectedTypes": [], | |
| "warnings": [f"Error: {str(e)}"] | |
| } | |
| demo = gr.Interface( | |
| fn=validate_schema, | |
| inputs=gr.Textbox(label="Enter URL to validate", placeholder="https://your-site.com/page"), | |
| outputs=gr.JSON(label="Validation Output"), | |
| title="AI Citation SEO – Trust Trail Validator", | |
| description="This tool checks for Trust Trail schema markup in a given URL and returns validation results." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |