Spaces:
Running
Running
| import streamlit as st | |
| import pandas as pd | |
| from typing import Dict, Any | |
| def render_analyzer_results(result: Dict[str, Any]) -> None: | |
| """Render AdAnalysis results in Streamlit UI (table format).""" | |
| # --- Headline --- | |
| if "copywriting_breakdown" in result: | |
| headline = result["copywriting_breakdown"].get("headline", "Ad Analysis Result") | |
| st.header(f" {headline}") | |
| # --- Visual Layout --- | |
| if "visual_structure_layout" in result: | |
| st.subheader(" Visual Structure Layout") | |
| vsl = result["visual_structure_layout"] | |
| table_data = [ | |
| ["Background", vsl.get("background_color")], | |
| ["Psychological Association", vsl.get("psychological_association")], | |
| ["Minimalism Level", vsl.get("minimalism_level")], | |
| ["Flow Summary", vsl.get("hierarchy", {}).get("flow_summary")], | |
| ["Key Elements Order", ", ".join(vsl.get("hierarchy", {}).get("key_elements_order", []))], | |
| ] | |
| df = pd.DataFrame(table_data, columns=["Property", "Value"]) | |
| st.table(df) | |
| # --- Psychological Triggers --- | |
| if "psychological_behavioral_triggers" in result: | |
| st.subheader(" Psychological & Behavioral Triggers") | |
| df = pd.DataFrame(result["psychological_behavioral_triggers"].items(), columns=["Trigger", "Description"]) | |
| st.table(df) | |
| # --- Storytelling --- | |
| if "story_creative_tells" in result: | |
| st.subheader(" Storytelling Elements") | |
| df = pd.DataFrame(result["story_creative_tells"].items(), columns=["Element", "Content"]) | |
| st.table(df) | |
| # --- Strengths & Weaknesses --- | |
| if "strengths" in result or "weaknesses" in result: | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| st.subheader("Strengths") | |
| strengths = result.get("strengths", []) | |
| if strengths: | |
| df = pd.DataFrame(strengths) | |
| df.rename(columns={"point": "Point", "why_it_matters": "Why It Matters"}, inplace=True) | |
| st.table(df) | |
| else: | |
| st.info("No strengths found.") | |
| with col2: | |
| st.subheader("Weaknesses") | |
| weaknesses = result.get("weaknesses", []) | |
| if weaknesses: | |
| df = pd.DataFrame(weaknesses) | |
| df.rename(columns={"point": "Point", "why_it_matters": "Why It Matters"}, inplace=True) | |
| st.table(df) | |
| else: | |
| st.info("No weaknesses found.") | |
| # --- Risks --- | |
| if "risks_in_arbitrage_context" in result: | |
| st.subheader(" Risks in Arbitrage Context") | |
| df = pd.DataFrame(result["risks_in_arbitrage_context"].items(), columns=["Risk", "Level"]) | |
| st.table(df) | |
| # --- Optimization Next Steps --- | |
| if "optimization_next_steps" in result: | |
| st.subheader(" Optimization Next Steps") | |
| opt = result["optimization_next_steps"] | |
| if "creative_variants" in opt: | |
| st.markdown("**Creative Variants**") | |
| df = pd.DataFrame(opt["creative_variants"]) | |
| df.rename( | |
| columns={ | |
| "hypothesis": "Hypothesis", | |
| "change": "Change", | |
| "expected_effect": "Expected Effect", | |
| "metric_to_watch": "Metric to Watch", | |
| }, | |
| inplace=True, | |
| ) | |
| st.table(df) | |
| with st.expander(" Raw JSON Result", expanded=False): | |
| st.json(result) | |