DBALP's picture
Update app.py
200ed0b verified
Raw History Blame Contribute Delete
3.67 kB
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"""
<div style="color:white; font-family:Arial; padding:20px; max-width:800px; margin:auto;">
<div style="text-align:center;">
<img src="{logo_url}" style="height:60px; margin-bottom:10px;" />
<h1 style="color:mediumpurple;">{name} - Media Authority Score</h1>
<h2 style="color:lightgray;">Total Score: {score}/120</h2>
</div>
<h3>🧠 Summary</h3>
<p>This is a placeholder summary. GPT will inject the final version here.</p>
<h3>✅ Strengths</h3>
<ul>
<li>Clear articulation of services/offering (Positioning)</li>
</ul>
<h3>🚨 Weaknesses</h3>
<ul>
<li>Online trust, reviews, and analytics proof significantly lacking</li>
</ul>
<h3>🔥 Big Opportunities</h3>
<ul>
<li>Build stronger digital authority through PR + trust signals</li>
<li>Increase perceived value using analytics and powerful brand voice</li>
</ul>
</div>
"""
return html, fig
except Exception as e:
return f"<p style='color:red;'>Error generating report: {str(e)}</p>", 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)