import gradio as gr import plotly.graph_objects as go import requests from bs4 import BeautifulSoup def fetch_logo(site_url): try: if not site_url.startswith("http"): site_url = "https://" + site_url # Try favicon first favicon = site_url.rstrip("/") + "/favicon.ico" response = requests.get(favicon, timeout=5) if response.status_code == 200: return favicon # Try to scrape for better logo response = requests.get(site_url, timeout=5) soup = BeautifulSoup(response.text, 'html.parser') for link in soup.find_all('link', rel=True): rels = link.get('rel') if isinstance(rels, list) and 'icon' in rels: href = link.get('href') if href.startswith('http'): return href else: return site_url.rstrip('/') + '/' + href.lstrip('/') except: pass # Default logo return "https://dontbealittlepitch.com/wp-content/uploads/2023/10/cropped-dontbealittlepitch-favicon-32x32.png" def render_report(): try: import urllib.parse as urlparse import os # Use os.environ as fallback (for Spaces bug workaround) qp = gr.Request.query_params if hasattr(gr, "Request") else {} name = qp.get("client", "Unnamed Client") domain = qp.get("site", "https://dontbealittlepitch.com") score = int(qp.get("score", 40)) section_scores = { "Authority Building": 7, "Media Presence": 7, "Storytelling": 11, "Reputation & Trust": 5, "Analytics & Proof": 5, "Voice & Authenticity": 5, } logo_url = fetch_logo(domain) fig = go.Figure(go.Bar( x=list(section_scores.values()), y=list(section_scores.keys()), orientation='h', marker=dict(color='mediumpurple'), )) fig.update_layout( template='plotly_dark', xaxis=dict(range=[0, 20]), title="Media Score Breakdown", height=400 ) html = f"""
This is a placeholder summary. GPT will inject the final version here.
Error generating report: {str(e)}
", go.Figure() with gr.Blocks(css="body { background-color: #111 !important; }") as demo: html_output = gr.HTML() chart_output = gr.Plot() demo.load(fn=render_report, outputs=[html_output, chart_output]) demo.launch(share=True)