Spaces:
Sleeping
Sleeping
| 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 | |
| """ | |
| ) | |