Spaces:
Running
Running
Upload 3 files
Browse files
components/image_render_analysis.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from typing import Dict, Any
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def render_analyzer_results(result: Dict[str, Any]) -> None:
|
| 7 |
+
"""Render AdAnalysis results in Streamlit UI (table format)."""
|
| 8 |
+
|
| 9 |
+
# --- Headline ---
|
| 10 |
+
if "copywriting_breakdown" in result:
|
| 11 |
+
headline = result["copywriting_breakdown"].get("headline", "Ad Analysis Result")
|
| 12 |
+
st.header(f" {headline}")
|
| 13 |
+
|
| 14 |
+
# --- Visual Layout ---
|
| 15 |
+
if "visual_structure_layout" in result:
|
| 16 |
+
st.subheader(" Visual Structure Layout")
|
| 17 |
+
vsl = result["visual_structure_layout"]
|
| 18 |
+
|
| 19 |
+
table_data = [
|
| 20 |
+
["Background", vsl.get("background_color")],
|
| 21 |
+
["Psychological Association", vsl.get("psychological_association")],
|
| 22 |
+
["Minimalism Level", vsl.get("minimalism_level")],
|
| 23 |
+
["Flow Summary", vsl.get("hierarchy", {}).get("flow_summary")],
|
| 24 |
+
["Key Elements Order", ", ".join(vsl.get("hierarchy", {}).get("key_elements_order", []))],
|
| 25 |
+
]
|
| 26 |
+
df = pd.DataFrame(table_data, columns=["Property", "Value"])
|
| 27 |
+
st.table(df)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
# --- Psychological Triggers ---
|
| 31 |
+
if "psychological_behavioral_triggers" in result:
|
| 32 |
+
st.subheader(" Psychological & Behavioral Triggers")
|
| 33 |
+
df = pd.DataFrame(result["psychological_behavioral_triggers"].items(), columns=["Trigger", "Description"])
|
| 34 |
+
st.table(df)
|
| 35 |
+
|
| 36 |
+
# --- Storytelling ---
|
| 37 |
+
if "story_creative_tells" in result:
|
| 38 |
+
st.subheader(" Storytelling Elements")
|
| 39 |
+
df = pd.DataFrame(result["story_creative_tells"].items(), columns=["Element", "Content"])
|
| 40 |
+
st.table(df)
|
| 41 |
+
|
| 42 |
+
# --- Strengths & Weaknesses ---
|
| 43 |
+
if "strengths" in result or "weaknesses" in result:
|
| 44 |
+
col1, col2 = st.columns(2)
|
| 45 |
+
|
| 46 |
+
with col1:
|
| 47 |
+
st.subheader("Strengths")
|
| 48 |
+
strengths = result.get("strengths", [])
|
| 49 |
+
if strengths:
|
| 50 |
+
df = pd.DataFrame(strengths)
|
| 51 |
+
df.rename(columns={"point": "Point", "why_it_matters": "Why It Matters"}, inplace=True)
|
| 52 |
+
st.table(df)
|
| 53 |
+
else:
|
| 54 |
+
st.info("No strengths found.")
|
| 55 |
+
|
| 56 |
+
with col2:
|
| 57 |
+
st.subheader("Weaknesses")
|
| 58 |
+
weaknesses = result.get("weaknesses", [])
|
| 59 |
+
if weaknesses:
|
| 60 |
+
df = pd.DataFrame(weaknesses)
|
| 61 |
+
df.rename(columns={"point": "Point", "why_it_matters": "Why It Matters"}, inplace=True)
|
| 62 |
+
st.table(df)
|
| 63 |
+
else:
|
| 64 |
+
st.info("No weaknesses found.")
|
| 65 |
+
|
| 66 |
+
# --- Risks ---
|
| 67 |
+
if "risks_in_arbitrage_context" in result:
|
| 68 |
+
st.subheader(" Risks in Arbitrage Context")
|
| 69 |
+
df = pd.DataFrame(result["risks_in_arbitrage_context"].items(), columns=["Risk", "Level"])
|
| 70 |
+
st.table(df)
|
| 71 |
+
|
| 72 |
+
# --- Optimization Next Steps ---
|
| 73 |
+
if "optimization_next_steps" in result:
|
| 74 |
+
st.subheader(" Optimization Next Steps")
|
| 75 |
+
opt = result["optimization_next_steps"]
|
| 76 |
+
|
| 77 |
+
if "creative_variants" in opt:
|
| 78 |
+
st.markdown("**Creative Variants**")
|
| 79 |
+
df = pd.DataFrame(opt["creative_variants"])
|
| 80 |
+
df.rename(
|
| 81 |
+
columns={
|
| 82 |
+
"hypothesis": "Hypothesis",
|
| 83 |
+
"change": "Change",
|
| 84 |
+
"expected_effect": "Expected Effect",
|
| 85 |
+
"metric_to_watch": "Metric to Watch",
|
| 86 |
+
},
|
| 87 |
+
inplace=True,
|
| 88 |
+
)
|
| 89 |
+
st.table(df)
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
with st.expander(" Raw JSON Result", expanded=False):
|
| 94 |
+
st.json(result)
|
| 95 |
+
|
components/render_analysis.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import json, pandas as pd, streamlit as st
|
| 2 |
from typing import Dict, Any
|
|
|
|
| 3 |
|
| 4 |
def _normalize_list(v):
|
| 5 |
if v is None: return []
|
|
@@ -14,14 +15,6 @@ def _to_dataframe(items, columns_map):
|
|
| 14 |
ordered_cols = [columns_map[k] for k in columns_map.keys() if columns_map[k] in df.columns]
|
| 15 |
return df.reindex(columns=ordered_cols)
|
| 16 |
|
| 17 |
-
def _mean_effectiveness(metrics):
|
| 18 |
-
if not metrics: return 0.0
|
| 19 |
-
scores = []
|
| 20 |
-
for m in metrics:
|
| 21 |
-
s = str(m.get("effectiveness_score", "0/10")).split("/")[0]
|
| 22 |
-
try: scores.append(int(s))
|
| 23 |
-
except Exception: pass
|
| 24 |
-
return round(sum(scores) / len(scores), 2) if scores else 0.0
|
| 25 |
|
| 26 |
def _search_dataframe(df, query):
|
| 27 |
if not query or df.empty: return df
|
|
@@ -130,11 +123,11 @@ def render_analyzer_results(analysis: Dict[str, Any]) -> None:
|
|
| 130 |
|
| 131 |
|
| 132 |
with tabs[4]:
|
| 133 |
-
|
| 134 |
-
st.code(
|
| 135 |
st.download_button(
|
| 136 |
"Download JSON",
|
| 137 |
-
data=
|
| 138 |
file_name="ad_analysis.json",
|
| 139 |
mime="application/json",
|
| 140 |
use_container_width=True
|
|
|
|
| 1 |
import json, pandas as pd, streamlit as st
|
| 2 |
from typing import Dict, Any
|
| 3 |
+
from helpers_function.helpers import _mean_effectiveness
|
| 4 |
|
| 5 |
def _normalize_list(v):
|
| 6 |
if v is None: return []
|
|
|
|
| 15 |
ordered_cols = [columns_map[k] for k in columns_map.keys() if columns_map[k] in df.columns]
|
| 16 |
return df.reindex(columns=ordered_cols)
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
def _search_dataframe(df, query):
|
| 20 |
if not query or df.empty: return df
|
|
|
|
| 123 |
|
| 124 |
|
| 125 |
with tabs[4]:
|
| 126 |
+
res = json.dumps(analysis, indent=2, ensure_ascii=False)
|
| 127 |
+
st.code(res, language="json")
|
| 128 |
st.download_button(
|
| 129 |
"Download JSON",
|
| 130 |
+
data=res.encode("utf-8"),
|
| 131 |
file_name="ad_analysis.json",
|
| 132 |
mime="application/json",
|
| 133 |
use_container_width=True
|