Spaces:
Sleeping
Sleeping
File size: 7,443 Bytes
47fa098 8e575c9 47fa098 64e8fdf 47fa098 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | import streamlit as st
import os
import warnings
from warnings import filterwarnings
from services.sentiment import detect_emotion
# ---------- Services ----------
from services.zero_shot import classify_intent
from services.sentiment import detect_emotion
from services.similarity import compute_similarity
from services.cta_analysis import analyze_cta
from services.copy_optimizer import optimize_copy
from services.meta_ads_api import fetch_live_ads
# ---------- Utils ----------
from utils.scoring import final_score
from utils.trend_analysis import market_trends
# ---------- Page Config ----------
st.set_page_config(
page_title="Meta AI Ads Intelligence Tool",
page_icon="π’",
layout="wide"
)
st.title("π’ Meta AI Ads Intelligence Tool")
st.caption("Live Meta Ads β’ Market Trends β’ AI Creative Analysis")
# ---------- Sidebar ----------
menu = st.sidebar.radio(
"Navigation",
[
"π Overview",
"π― Analyze My Ad",
"π§ Live Competitor Ads",
"β οΈ Ad Fatigue Checker",
"βοΈ Copy Optimizer",
"βΉοΈ About"
]
)
# =========================================================
# π OVERVIEW
# =========================================================
if menu == "π Overview":
st.subheader("What does this tool do?")
st.write(
"""
This platform combines **Meta Ads Library live data** with **pretrained AI models**
to analyze ad creatives, market trends, and competitor messaging β without using
any historical performance data.
"""
)
col1, col2, col3 = st.columns(3)
col1.metric("Live Meta Ads", "Yes")
col2.metric("Model Training", "Not Required")
col3.metric("Analysis Type", "Real-Time")
st.info("π No ads are stored. All analysis runs on demand.")
# =========================================================
# π― ANALYZE USER AD
# =========================================================
elif menu == "π― Analyze My Ad":
st.subheader("Analyze Your Ad Creative")
col1, col2 = st.columns(2)
with col1:
caption = st.text_area("Ad Caption / Primary Text", height=150)
cta = st.selectbox(
"Call To Action",
["Buy Now", "Shop Now", "Learn More", "DM Us", "Sign Up", "Check It Out"]
)
analyze = st.button("Analyze Ad")
with col2:
if analyze and caption.strip():
with st.spinner("Running AI analysis..."):
intent = classify_intent(caption)
emotion = detect_emotion(caption)
quality = text_quality_score(caption)
cta_score = cta_strength(cta)
score = final_score(
intent["score"],
emotion["score"],
cta_score,
quality
)
st.metric("Performance Score", f"{score}/100")
if score >= 75:
st.success("π’ Low Risk β Ready to Run")
elif score >= 50:
st.warning("π‘ Medium Risk β Needs Optimization")
else:
st.error("π΄ High Risk β Likely Budget Waste")
st.progress(score / 100)
st.markdown("### π AI Insights")
st.write(f"**Intent:** {intent['label']}")
st.write(f"**Emotion:** {emotion['emotion']}")
st.write(f"**CTA Strength:** {round(cta_score * 100)}%")
st.write(f"**Text Quality:** {round(quality * 100)}%")
# =========================================================
# π§ LIVE COMPETITOR ADS (META ADS LIBRARY)
# =========================================================
elif menu == "π§ Live Competitor Ads":
st.subheader("Live Competitor Ads (Meta Ads Library)")
keyword = st.text_input("Search Keyword / Brand / Product")
country = st.selectbox("Country", ["IN", "US", "UK", "AE"])
if st.button("Fetch Live Ads"):
try:
with st.spinner("Fetching live ads from Meta Ads Library..."):
ads = fetch_live_ads(keyword, country)
if not ads:
st.warning("No ads found for this keyword.")
else:
st.success(f"Fetched {len(ads)} live ads")
# ---------- Market Trends ----------
trends = market_trends(ads)
st.markdown("### π Market Trend Analysis")
st.write("**Total Live Ads:**", trends["total_ads"])
st.write("**Trending Keywords:**", ", ".join(trends["top_keywords"]))
st.divider()
# ---------- Show Ads + AI Analysis ----------
for ad in ads[:5]:
st.markdown(f"### π·οΈ {ad['page_name']}")
st.write(ad["ad_creative_body"])
intent = classify_intent(ad["ad_creative_body"])
emotion = detect_emotion(ad["ad_creative_body"])
st.caption(
f"Intent: {intent['label']} | "
f"Emotion: {emotion['emotion']}"
)
st.divider()
except Exception as e:
st.error(f"Error fetching ads: {e}")
# =========================================================
# β οΈ AD FATIGUE CHECKER
# =========================================================
elif menu == "β οΈ Ad Fatigue Checker":
st.subheader("Ad Fatigue Risk Estimator")
caption = st.text_area("Ad Caption", height=120)
days = st.slider("Planned Run Duration (Days)", 1, 30, 7)
frequency = st.slider("Estimated Frequency", 1.0, 5.0, 2.0)
if st.button("Check Fatigue"):
fatigue_risk = min((days * frequency) / 30, 1.0)
st.metric("Fatigue Risk", f"{round(fatigue_risk * 100)}%")
st.progress(fatigue_risk)
if fatigue_risk > 0.7:
st.error("High Fatigue Risk β Refresh Creative")
elif fatigue_risk > 0.4:
st.warning("Medium Risk β Monitor Performance")
else:
st.success("Low Risk β Safe to Run")
# =========================================================
# βοΈ COPY OPTIMIZER
# =========================================================
elif menu == "βοΈ Copy Optimizer":
st.subheader("AI Copy Optimization")
caption = st.text_area("Original Caption", height=150)
if st.button("Get Suggestions") and caption.strip():
tips = optimize_copy(caption)
if tips:
st.markdown("### β¨ Optimization Suggestions")
for tip in tips:
st.write("β’", tip)
else:
st.success("Your caption already follows best practices!")
# =========================================================
# βΉοΈ ABOUT
# =========================================================
elif menu == "βΉοΈ About":
st.subheader("About This Project")
st.write(
"""
**Meta AI Ads Intelligence Tool** is a real-time marketing intelligence platform.
### Key Capabilities
- Live Meta Ads Library integration
- Market trend analysis
- Zero-shot intent classification
- Emotion detection
- No model training or historical data
### Tech Stack
- Python
- Streamlit
- HuggingFace Transformers
- Meta Ads Library API
"""
)
|