vaibhavbasidoni's picture
Initial commit: Startup Validator multi-agent system
65ade69
Raw History Blame Contribute Delete
29.9 kB
import streamlit as st
import time
import re
import io
from datetime import datetime
from fpdf import FPDF
from dotenv import load_dotenv
from src.graph import app
from src.state import AgentState
# Load environment variables (API Keys) from .env
load_dotenv()
st.set_page_config(page_title="Startup Validator", page_icon="πŸš€", layout="wide")
# ──────────────────────────────────────────────
# INIT CACHE
# ──────────────────────────────────────────────
if "cache" not in st.session_state:
st.session_state.cache = {}
# ──────────────────────────────────────────────
# PDF REPORT GENERATOR
# ──────────────────────────────────────────────
def _clean(text: str) -> str:
"""Strip markdown and non-latin chars for PDF."""
text = re.sub(r'\*\*(.+?)\*\*', r'\1', text)
text = re.sub(r'\*(.+?)\*', r'\1', text)
return text.encode("latin-1", "replace").decode("latin-1")
def generate_pdf(idea, score, verdict, summary, all_results):
pdf = FPDF()
pdf.set_auto_page_break(auto=True, margin=15)
pdf.add_page()
# ── Title ──
pdf.set_font("Helvetica", "B", 26)
pdf.set_text_color(55, 48, 107)
pdf.cell(0, 16, "Startup Validator Report", ln=True, align="C")
pdf.set_font("Helvetica", "", 9)
pdf.set_text_color(140, 140, 140)
pdf.cell(0, 7, f"Generated on {datetime.now().strftime('%B %d, %Y at %I:%M %p')}", ln=True, align="C")
pdf.ln(6)
# ── Thin line ──
pdf.set_draw_color(200, 200, 220)
pdf.line(15, pdf.get_y(), 195, pdf.get_y())
pdf.ln(8)
# ── Startup Idea ──
pdf.set_text_color(40, 40, 40)
pdf.set_font("Helvetica", "B", 13)
pdf.cell(0, 9, "Startup Idea", ln=True)
pdf.set_font("Helvetica", "", 11)
pdf.multi_cell(0, 6.5, _clean(idea))
pdf.ln(6)
# ── Score & Verdict ──
pdf.set_font("Helvetica", "B", 13)
pdf.cell(0, 9, "Evaluation", ln=True)
# Colored verdict box
if verdict == "Go":
pdf.set_fill_color(5, 150, 105)
elif verdict == "Caution":
pdf.set_fill_color(217, 119, 6)
else:
pdf.set_fill_color(220, 38, 38)
pdf.set_font("Helvetica", "B", 14)
pdf.set_text_color(255, 255, 255)
pdf.cell(50, 10, f" Score: {score}/100", fill=True, new_x="RIGHT", new_y="TOP")
pdf.cell(5, 10, "")
pdf.cell(40, 10, f" {verdict}", fill=True, ln=True)
pdf.ln(6)
# ── Executive Summary ──
pdf.set_text_color(40, 40, 40)
pdf.set_font("Helvetica", "B", 13)
pdf.cell(0, 9, "Executive Summary", ln=True)
pdf.set_font("Helvetica", "", 10.5)
pdf.multi_cell(0, 6, _clean(summary))
pdf.ln(6)
pdf.set_draw_color(200, 200, 220)
pdf.line(15, pdf.get_y(), 195, pdf.get_y())
pdf.ln(6)
# ── Agent Reports ──
pdf.set_font("Helvetica", "B", 15)
pdf.set_text_color(55, 48, 107)
pdf.cell(0, 10, "Detailed Agent Reports", ln=True)
pdf.ln(3)
agent_labels = {
"competitor_analysis": "Competitor Analysis",
"market_sizing": "Market Sizing",
"community_sentiment": "Community Sentiment",
"os_risk": "Open-Source Risk",
}
for result in all_results:
agent_key = result.get("agent", "unknown")
label = agent_labels.get(agent_key, agent_key.replace("_", " ").title())
findings = result.get("findings", "No findings.")
sources = result.get("sources", [])
# Agent heading
pdf.set_font("Helvetica", "B", 12)
pdf.set_text_color(60, 60, 60)
pdf.cell(0, 8, label, ln=True)
# Findings
pdf.set_font("Helvetica", "", 10)
pdf.set_text_color(70, 70, 70)
pdf.multi_cell(0, 5.5, _clean(findings))
# Sources
if sources:
pdf.set_font("Helvetica", "I", 8.5)
pdf.set_text_color(90, 90, 180)
for src in sources:
link_text = _clean(f" [{src.get('domain', '')}] {src.get('title', '')[:60]}")
pdf.cell(0, 4.5, link_text, ln=True, link=src.get("url", ""))
pdf.set_text_color(70, 70, 70)
pdf.ln(5)
# ── Footer ──
pdf.ln(8)
pdf.set_font("Helvetica", "I", 8)
pdf.set_text_color(160, 160, 160)
pdf.cell(0, 5, "Generated by Startup Validator - AI Multi-Agent System", ln=True, align="C")
return bytes(pdf.output())
# ──────────────────────────────────────────────
# PREMIUM CSS
# ──────────────────────────────────────────────
st.markdown("""
<style>
/* ── Google Font ── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');
/* ── Hide Streamlit chrome ── */
#MainMenu, footer, header {visibility: hidden;}
/* ── Global ── */
.stApp {
font-family: 'Inter', sans-serif;
}
/* ── Hero Header ── */
.hero {
background: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
border-radius: 24px;
padding: 3rem 2rem 2.5rem;
text-align: center;
position: relative;
overflow: hidden;
border: 1px solid rgba(255,255,255,0.08);
margin-bottom: 2rem;
}
.hero::before {
content: '';
position: absolute;
inset: 0;
background: radial-gradient(circle at 30% 40%, rgba(102,126,234,0.25) 0%, transparent 60%),
radial-gradient(circle at 70% 60%, rgba(118,75,162,0.20) 0%, transparent 50%);
pointer-events: none;
}
.hero-emoji { font-size: 3rem; margin-bottom: 0.5rem; position: relative; z-index: 1; }
.hero-title {
font-size: 2.6rem;
font-weight: 900;
background: linear-gradient(135deg, #a78bfa, #818cf8, #6366f1);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
position: relative; z-index: 1;
letter-spacing: -0.5px;
}
.hero-sub {
color: rgba(255,255,255,0.65);
font-size: 1.05rem;
font-weight: 400;
margin-top: 0.4rem;
position: relative; z-index: 1;
}
/* ── Feature pills ── */
.pills { display: flex; flex-wrap: wrap; gap: 0.6rem; justify-content: center; margin-top: 1.5rem; position: relative; z-index: 1; }
.pill {
background: rgba(255,255,255,0.06);
border: 1px solid rgba(255,255,255,0.12);
border-radius: 50px;
padding: 0.45rem 1.1rem;
font-size: 0.82rem;
font-weight: 500;
color: rgba(255,255,255,0.8);
backdrop-filter: blur(8px);
display: flex; align-items: center; gap: 0.4rem;
transition: all 0.3s ease;
}
.pill:hover { background: rgba(255,255,255,0.12); border-color: rgba(167,139,250,0.4); transform: translateY(-1px); }
/* ── Section headings ── */
.section-title {
font-size: 1.3rem;
font-weight: 700;
margin-bottom: 1rem;
display: flex; align-items: center; gap: 0.5rem;
}
/* ── Status rows ── */
.status-row {
display: flex; align-items: center; gap: 0.75rem;
padding: 0.7rem 1rem;
border-radius: 12px;
margin-bottom: 0.45rem;
font-weight: 500;
font-size: 0.92rem;
transition: all 0.4s ease;
}
.status-waiting {
background: rgba(255,255,255,0.03);
border: 1px solid rgba(255,255,255,0.06);
color: rgba(255,255,255,0.45);
}
.status-running {
background: linear-gradient(135deg, rgba(99,102,241,0.12), rgba(167,139,250,0.08));
border: 1px solid rgba(99,102,241,0.25);
color: rgba(167,139,250,0.95);
animation: pulse-border 2s ease-in-out infinite;
}
@keyframes pulse-border {
0%,100% { border-color: rgba(99,102,241,0.20); }
50% { border-color: rgba(99,102,241,0.50); }
}
.status-done {
background: linear-gradient(135deg, rgba(16,185,129,0.10), rgba(52,211,153,0.06));
border: 1px solid rgba(16,185,129,0.25);
color: rgba(52,211,153,0.95);
}
.status-dot {
width: 8px; height: 8px; border-radius: 50%;
flex-shrink: 0;
}
.dot-waiting { background: rgba(255,255,255,0.2); }
.dot-running { background: #818cf8; animation: blink 1.2s ease-in-out infinite; }
@keyframes blink { 0%,100%{opacity:1;} 50%{opacity:0.3;} }
.dot-done { background: #34d399; }
/* ── Verdict card ── */
.verdict-card {
background: linear-gradient(145deg, rgba(255,255,255,0.05), rgba(255,255,255,0.02));
border: 1px solid rgba(255,255,255,0.08);
border-radius: 24px;
padding: 2.5rem 2rem;
text-align: center;
backdrop-filter: blur(12px);
}
.score-big {
font-size: 4.5rem;
font-weight: 900;
line-height: 1;
margin-bottom: 0.3rem;
letter-spacing: -2px;
}
.score-label {
font-size: 0.85rem;
font-weight: 500;
text-transform: uppercase;
letter-spacing: 3px;
color: rgba(255,255,255,0.4);
margin-bottom: 1.2rem;
}
.verdict-badge {
display: inline-block;
padding: 0.55rem 2rem;
border-radius: 50px;
font-weight: 700;
font-size: 1rem;
text-transform: uppercase;
letter-spacing: 2.5px;
}
.badge-go { background: linear-gradient(135deg, #059669, #34d399); color: #fff; box-shadow: 0 4px 20px rgba(5,150,105,0.3); }
.badge-caution { background: linear-gradient(135deg, #d97706, #fbbf24); color: #1a1a2e; box-shadow: 0 4px 20px rgba(217,119,6,0.3); }
.badge-nogo { background: linear-gradient(135deg, #dc2626, #f87171); color: #fff; box-shadow: 0 4px 20px rgba(220,38,38,0.3); }
/* ── Summary card ── */
.summary-card {
background: linear-gradient(145deg, rgba(255,255,255,0.05), rgba(255,255,255,0.02));
border: 1px solid rgba(255,255,255,0.08);
border-radius: 24px;
padding: 2rem;
backdrop-filter: blur(12px);
height: 100%;
display: flex; flex-direction: column;
}
.summary-label {
font-size: 1.1rem;
font-weight: 700;
margin-bottom: 1rem;
display: flex; align-items: center; gap: 0.5rem;
}
.summary-body {
font-size: 0.98rem;
line-height: 1.85;
color: rgba(255,255,255,0.75);
padding: 1.25rem;
background: rgba(255,255,255,0.02);
border-radius: 14px;
border-left: 3px solid #818cf8;
flex: 1;
}
/* ── Agent report cards ── */
.report-card {
background: linear-gradient(145deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01));
border: 1px solid rgba(255,255,255,0.07);
border-radius: 20px;
padding: 1.5rem;
margin-bottom: 1rem;
transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
position: relative;
overflow: hidden;
}
.report-card:hover {
border-color: rgba(129,140,248,0.35);
transform: translateY(-3px);
box-shadow: 0 12px 40px rgba(99,102,241,0.12);
}
.report-card::before {
content: '';
position: absolute;
top: 0; left: 0;
width: 100%; height: 3px;
}
.report-card.rc-competitor::before { background: linear-gradient(90deg, #667eea, #764ba2); }
.report-card.rc-market::before { background: linear-gradient(90deg, #764ba2, #a78bfa); }
.report-card.rc-sentiment::before { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.report-card.rc-osrisk::before { background: linear-gradient(90deg, #ef4444, #f87171); }
.rc-header {
display: flex; align-items: center; gap: 0.7rem;
margin-bottom: 1rem;
}
.rc-icon {
width: 38px; height: 38px;
border-radius: 10px;
display: flex; align-items: center; justify-content: center;
font-size: 1.1rem;
flex-shrink: 0;
}
.rc-icon-comp { background: linear-gradient(135deg, #667eea, #764ba2); }
.rc-icon-mkt { background: linear-gradient(135deg, #764ba2, #a78bfa); }
.rc-icon-sent { background: linear-gradient(135deg, #f59e0b, #fbbf24); }
.rc-icon-osr { background: linear-gradient(135deg, #ef4444, #f87171); }
.rc-title { font-weight: 700; font-size: 1rem; color: #e2e8f0; }
.rc-body {
font-size: 0.9rem;
line-height: 1.75;
color: rgba(255,255,255,0.7);
}
/* ── ChatGPT-style source pills ── */
.sources-section {
margin-top: 1.1rem;
padding-top: 0.9rem;
border-top: 1px solid rgba(255,255,255,0.06);
}
.sources-label {
font-size: 0.7rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 1.5px;
color: rgba(255,255,255,0.3);
margin-bottom: 0.55rem;
}
.sources-row {
display: flex;
flex-wrap: wrap;
gap: 0.45rem;
}
.source-pill {
display: inline-flex;
align-items: center;
gap: 0.45rem;
background: rgba(255,255,255,0.04);
border: 1px solid rgba(255,255,255,0.08);
border-radius: 10px;
padding: 0.4rem 0.75rem;
text-decoration: none !important;
color: rgba(255,255,255,0.65) !important;
font-size: 0.78rem;
font-weight: 500;
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
max-width: 260px;
cursor: pointer;
}
.source-pill:hover {
background: rgba(99,102,241,0.12);
border-color: rgba(99,102,241,0.35);
color: #a78bfa !important;
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(99,102,241,0.15);
}
.source-favicon {
width: 14px;
height: 14px;
border-radius: 3px;
flex-shrink: 0;
opacity: 0.85;
}
.source-num {
width: 17px;
height: 17px;
border-radius: 50%;
background: rgba(99,102,241,0.2);
color: #a78bfa;
display: flex;
align-items: center;
justify-content: center;
font-size: 0.6rem;
font-weight: 700;
flex-shrink: 0;
line-height: 1;
}
.source-text {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
line-height: 1.2;
}
.source-domain {
font-size: 0.65rem;
color: rgba(255,255,255,0.3);
margin-left: auto;
padding-left: 0.4rem;
flex-shrink: 0;
}
/* ── Time badge ── */
.time-badge {
display: inline-block;
background: linear-gradient(135deg, rgba(99,102,241,0.2), rgba(167,139,250,0.15));
border: 1px solid rgba(99,102,241,0.3);
color: #a78bfa;
padding: 0.4rem 1.4rem;
border-radius: 50px;
font-weight: 600;
font-size: 0.88rem;
letter-spacing: 0.3px;
}
/* ── Cache badge ── */
.cache-badge {
display: inline-flex;
align-items: center;
gap: 0.4rem;
background: linear-gradient(135deg, rgba(52,211,153,0.12), rgba(16,185,129,0.08));
border: 1px solid rgba(52,211,153,0.25);
color: #34d399;
padding: 0.4rem 1.4rem;
border-radius: 50px;
font-weight: 600;
font-size: 0.88rem;
}
/* ── Divider ── */
.glow-divider {
height: 1px;
background: linear-gradient(90deg, transparent, rgba(99,102,241,0.4), transparent);
margin: 2rem 0;
border: none;
}
/* ── Button override ── */
.stButton > button {
background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%) !important;
color: white !important;
border: none !important;
border-radius: 14px !important;
padding: 0.8rem 2rem !important;
font-weight: 700 !important;
font-size: 1.05rem !important;
letter-spacing: 0.3px !important;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
width: 100% !important;
box-shadow: 0 4px 15px rgba(99,102,241,0.25) !important;
}
.stButton > button:hover {
transform: translateY(-2px) !important;
box-shadow: 0 8px 30px rgba(99,102,241,0.4) !important;
}
.stButton > button:active {
transform: translateY(0) !important;
}
/* ── Download button override ── */
.stDownloadButton > button {
background: linear-gradient(135deg, rgba(99,102,241,0.15), rgba(167,139,250,0.10)) !important;
color: #a78bfa !important;
border: 1px solid rgba(99,102,241,0.3) !important;
border-radius: 12px !important;
padding: 0.65rem 1.5rem !important;
font-weight: 600 !important;
font-size: 0.92rem !important;
transition: all 0.3s ease !important;
width: 100% !important;
}
.stDownloadButton > button:hover {
background: linear-gradient(135deg, rgba(99,102,241,0.25), rgba(167,139,250,0.18)) !important;
border-color: rgba(99,102,241,0.5) !important;
transform: translateY(-1px) !important;
box-shadow: 0 4px 20px rgba(99,102,241,0.2) !important;
}
/* ── Text area ── */
.stTextArea textarea {
border-radius: 14px !important;
border: 1px solid rgba(255,255,255,0.1) !important;
background: rgba(255,255,255,0.03) !important;
font-size: 1rem !important;
padding: 1rem !important;
transition: border-color 0.3s ease !important;
}
.stTextArea textarea:focus {
border-color: rgba(99,102,241,0.5) !important;
box-shadow: 0 0 0 3px rgba(99,102,241,0.1) !important;
}
/* ── Footer ── */
.app-footer {
text-align: center;
padding: 2rem 0 1rem;
color: rgba(255,255,255,0.25);
font-size: 0.8rem;
font-weight: 400;
}
.app-footer a { color: rgba(167,139,250,0.6); text-decoration: none; }
</style>
""", unsafe_allow_html=True)
# ──────────────────────────────────────────────
# HERO HEADER
# ──────────────────────────────────────────────
st.markdown("""
<div class="hero">
<div class="hero-emoji">πŸš€</div>
<div class="hero-title">Startup Validator</div>
<div class="hero-sub">AI-Powered Multi-Agent Due Diligence β€” in Seconds</div>
<div class="pills">
<div class="pill">πŸ” Competitor Analysis</div>
<div class="pill">πŸ“Š Market Sizing</div>
<div class="pill">πŸ’¬ Community Sentiment</div>
<div class="pill">⚠️ Open-Source Risk</div>
</div>
</div>
""", unsafe_allow_html=True)
# ──────────────────────────────────────────────
# INPUT
# ──────────────────────────────────────────────
idea = st.text_area(
"πŸ’‘ Describe your startup idea",
height=120,
placeholder="e.g., A marketplace for renting out private swimming pools by the hour…",
)
if st.button("⚑ Validate My Idea", type="primary"):
if not idea.strip():
st.warning("Please enter an idea first.")
else:
st.markdown('<div class="glow-divider"></div>', unsafe_allow_html=True)
idea_key = idea.strip().lower()
is_cached = idea_key in st.session_state.cache
# ── Agent metadata ──
agent_meta = {
"competitor_agent": {"icon": "πŸ”", "label": "Competitor Analysis"},
"market_sizing_agent": {"icon": "πŸ“Š", "label": "Market Sizing"},
"sentiment_agent": {"icon": "πŸ’¬", "label": "Community Sentiment"},
"os_risk_agent": {"icon": "⚠️", "label": "Open-Source Risk"},
"scoring_node": {"icon": "🧠", "label": "Scoring Engine"},
}
if is_cached:
# ──────────────────────────────────
# CACHED RESULT β€” instant display
# ──────────────────────────────────
cached = st.session_state.cache[idea_key]
final_state = cached["final_state"]
all_results = cached["all_results"]
elapsed = cached["elapsed"]
st.markdown(
'<div style="text-align:center; margin-top:0.5rem;">'
'<span class="cache-badge">⚑ Cached result β€” instant load</span></div>',
unsafe_allow_html=True,
)
else:
# ──────────────────────────────────
# FRESH RUN β€” stream with progress bar
# ──────────────────────────────────
st.markdown('<div class="section-title">πŸ€– Agent Execution</div>', unsafe_allow_html=True)
# Status placeholders
status_ph = {}
for key, meta in agent_meta.items():
status_ph[key] = st.empty()
status_ph[key].markdown(
f'<div class="status-row status-waiting">'
f'<span class="status-dot dot-waiting"></span>'
f'{meta["icon"]} {meta["label"]} β€” Waiting…</div>',
unsafe_allow_html=True,
)
# Progress bar (5 nodes: 4 agents + 1 scoring = 20% each)
progress_bar = st.progress(0, text="Starting agents…")
initial_state: AgentState = {
"idea": idea,
"results": [],
"score": 0,
"verdict": "",
"summary": "",
}
start_time = time.time()
final_state = None
all_results = []
nodes_done = 0
for chunk in app.stream(initial_state, stream_mode="updates"):
for node_name, state_update in chunk.items():
nodes_done += 1
pct = min(nodes_done / 5, 1.0)
if node_name in status_ph:
meta = agent_meta[node_name]
status_ph[node_name].markdown(
f'<div class="status-row status-done">'
f'<span class="status-dot dot-done"></span>'
f'βœ… {meta["icon"]} {meta["label"]} β€” Complete</div>',
unsafe_allow_html=True,
)
# Update progress bar
if pct < 1.0:
progress_bar.progress(pct, text=f"Agents working… {int(pct * 100)}%")
else:
progress_bar.progress(1.0, text="All agents finished!")
# Collect results
if "results" in state_update:
all_results.extend(state_update["results"])
if node_name == "scoring_node":
final_state = state_update
elapsed = time.time() - start_time
# Cache the results
st.session_state.cache[idea_key] = {
"final_state": final_state,
"all_results": all_results,
"elapsed": elapsed,
}
st.markdown(
f'<div style="text-align:center; margin-top:1rem;">'
f'<span class="time-badge">✨ Validated in {elapsed:.1f}s</span></div>',
unsafe_allow_html=True,
)
st.markdown('<div class="glow-divider"></div>', unsafe_allow_html=True)
# ──────────────────────────────────────
# VERDICT + SUMMARY (shared path)
# ──────────────────────────────────────
if final_state:
score = final_state["score"]
verdict = final_state["verdict"]
summary = final_state["summary"]
# Style by verdict
if verdict == "Go":
badge_cls = "badge-go"
score_grad = "linear-gradient(135deg, #059669, #34d399)"
elif verdict == "Caution":
badge_cls = "badge-caution"
score_grad = "linear-gradient(135deg, #d97706, #fbbf24)"
else:
badge_cls = "badge-nogo"
score_grad = "linear-gradient(135deg, #dc2626, #f87171)"
col_v, col_s = st.columns([1, 2], gap="large")
with col_v:
st.markdown(f"""
<div class="verdict-card">
<div class="score-big" style="background:{score_grad};-webkit-background-clip:text;-webkit-text-fill-color:transparent;">
{score}
</div>
<div class="score-label">confidence score</div>
<div class="verdict-badge {badge_cls}">{verdict}</div>
</div>
""", unsafe_allow_html=True)
with col_s:
st.markdown(f"""
<div class="summary-card">
<div class="summary-label">πŸ“‹ Executive Summary</div>
<div class="summary-body">{summary}</div>
</div>
""", unsafe_allow_html=True)
st.markdown('<div class="glow-divider"></div>', unsafe_allow_html=True)
# ──────────────────────────────────
# INDIVIDUAL AGENT REPORTS
# ──────────────────────────────────
st.markdown('<div class="section-title">πŸ“‘ Detailed Agent Reports</div>', unsafe_allow_html=True)
report_style = {
"competitor_analysis": {"cls": "rc-competitor", "icon_cls": "rc-icon-comp", "icon": "πŸ”", "label": "Competitor Analysis"},
"market_sizing": {"cls": "rc-market", "icon_cls": "rc-icon-mkt", "icon": "πŸ“Š", "label": "Market Sizing"},
"community_sentiment": {"cls": "rc-sentiment", "icon_cls": "rc-icon-sent", "icon": "πŸ’¬", "label": "Community Sentiment"},
"os_risk": {"cls": "rc-osrisk", "icon_cls": "rc-icon-osr", "icon": "⚠️", "label": "Open-Source Risk"},
}
# 2 Γ— 2 grid
left_col, right_col = st.columns(2, gap="medium")
for idx, result in enumerate(all_results):
agent_key = result.get("agent", "unknown")
style = report_style.get(agent_key, {"cls": "rc-competitor", "icon_cls": "rc-icon-comp", "icon": "πŸ“„", "label": agent_key})
findings = result.get("findings", "No findings available.")
sources = result.get("sources", [])
# Escape any stray HTML in LLM output but keep line breaks
findings_html = findings.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace("\n", "<br>")
# Convert markdown bold/italic to HTML
findings_html = re.sub(r'\*\*(.+?)\*\*', r'<strong>\1</strong>', findings_html)
findings_html = re.sub(r'\*(.+?)\*', r'<em>\1</em>', findings_html)
# Build source pills HTML (ChatGPT-style)
sources_html = ""
if sources:
pills = ""
for i, src in enumerate(sources):
favicon = f"https://www.google.com/s2/favicons?domain={src['domain']}&sz=32"
title = src['title'][:42]
domain = src['domain'][:25]
pills += (
f'<a href="{src["url"]}" target="_blank" rel="noopener" class="source-pill">'
f'<img src="{favicon}" class="source-favicon" onerror="this.style.display=\'none\'">'
f'<span class="source-num">{i + 1}</span>'
f'<span class="source-text">{title}</span>'
f'<span class="source-domain">{domain}</span>'
f'</a>'
)
sources_html = (
f'<div class="sources-section">'
f'<div class="sources-label">Sources</div>'
f'<div class="sources-row">{pills}</div>'
f'</div>'
)
card_html = f"""
<div class="report-card {style['cls']}">
<div class="rc-header">
<div class="rc-icon {style['icon_cls']}">{style['icon']}</div>
<div class="rc-title">{style['label']}</div>
</div>
<div class="rc-body">{findings_html}</div>
{sources_html}
</div>
"""
if idx % 2 == 0:
with left_col:
st.markdown(card_html, unsafe_allow_html=True)
else:
with right_col:
st.markdown(card_html, unsafe_allow_html=True)
st.markdown('<div class="glow-divider"></div>', unsafe_allow_html=True)
# ──────────────────────────────────
# PDF DOWNLOAD BUTTON
# ──────────────────────────────────
pdf_bytes = generate_pdf(idea, score, verdict, summary, all_results)
timestamp = datetime.now().strftime("%Y%m%d_%H%M")
dl_col1, dl_col2, dl_col3 = st.columns([1, 1, 1])
with dl_col2:
st.download_button(
label="πŸ“„ Download PDF Report",
data=pdf_bytes,
file_name=f"startup_validation_{timestamp}.pdf",
mime="application/pdf",
)
# ── Footer ──
st.markdown(
'<div class="app-footer">Built with LangGraph &bull; Powered by GPT-4o-mini</div>',
unsafe_allow_html=True,
)