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(""" """, unsafe_allow_html=True) # ────────────────────────────────────────────── # HERO HEADER # ────────────────────────────────────────────── st.markdown("""
πŸš€
Startup Validator
AI-Powered Multi-Agent Due Diligence β€” in Seconds
πŸ” Competitor Analysis
πŸ“Š Market Sizing
πŸ’¬ Community Sentiment
⚠️ Open-Source Risk
""", 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('
', 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( '
' '⚑ Cached result β€” instant load
', unsafe_allow_html=True, ) else: # ────────────────────────────────── # FRESH RUN β€” stream with progress bar # ────────────────────────────────── st.markdown('
πŸ€– Agent Execution
', 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'
' f'' f'{meta["icon"]} {meta["label"]} β€” Waiting…
', 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'
' f'' f'βœ… {meta["icon"]} {meta["label"]} β€” Complete
', 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'
' f'✨ Validated in {elapsed:.1f}s
', unsafe_allow_html=True, ) st.markdown('
', 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"""
{score}
confidence score
{verdict}
""", unsafe_allow_html=True) with col_s: st.markdown(f"""
πŸ“‹ Executive Summary
{summary}
""", unsafe_allow_html=True) st.markdown('
', unsafe_allow_html=True) # ────────────────────────────────── # INDIVIDUAL AGENT REPORTS # ────────────────────────────────── st.markdown('
πŸ“‘ Detailed Agent Reports
', 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("&", "&").replace("<", "<").replace(">", ">").replace("\n", "
") # Convert markdown bold/italic to HTML findings_html = re.sub(r'\*\*(.+?)\*\*', r'\1', findings_html) findings_html = re.sub(r'\*(.+?)\*', r'\1', 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'' f'' f'{i + 1}' f'{title}' f'{domain}' f'' ) sources_html = ( f'
' f'
Sources
' f'
{pills}
' f'
' ) card_html = f"""
{style['icon']}
{style['label']}
{findings_html}
{sources_html}
""" 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('
', 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( '', unsafe_allow_html=True, )