Skip to content

KHUSHEEdengale/AdPulse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AdPulse Banner

AdPulse β€” AI-Powered Campaign Intelligence Platform

ML-driven revenue prediction, explainability (SHAP + LIME), and real-time campaign optimization for digital advertising.

Features FastAPI XGBoost SHAP License

Quick Start β€’ Features β€’ Architecture β€’ API Reference β€’ Model Performance


🎯 Overview

AdPulse is a full-stack campaign intelligence system that combines machine learning, explainable AI, and real-time analytics to help marketing teams predict revenue, understand model decisions, and optimize ad spend across channels.

AdPulse goes beyond simple predictions β€” it provides actionable insights backed by SHAP/LIME explanations, budget optimization, and AI-powered campaign analysis.

What Makes AdPulse Different?

Traditional Analytics AdPulse
Backward-looking reports Predictive revenue forecasting
Black-box models SHAP + LIME explainability
Manual budget allocation ROAS-weighted auto-optimization
Static dashboards Real-time interactive intelligence
No risk detection ML-powered anomaly alerts

✨ Features

πŸ“Š Analytics & Prediction

  • Revenue Prediction Engine β€” XGBoost + LightGBM ensemble with RΒ² = 0.993 accuracy
  • Spend Sensitivity Analysis β€” Revenue impact curves across Β±50% spend scenarios
  • Campaign Health Scoring β€” Composite metric combining intent, quality, and efficiency
  • Risk Detection β€” Automatic flagging of underperforming campaigns

🧠 Explainable AI (XAI)

  • SHAP Global Explanations β€” Top revenue drivers ranked by impact magnitude
  • SHAP Dependence Plots β€” Visualize how individual features influence predictions
  • LIME Local Explanations β€” Instance-level model explanations for any campaign
  • Business Insight Narratives β€” Auto-generated human-readable recommendations

πŸ€– AI-Powered Tools

  • Campaign Chat Analyst β€” GPT-4o-mini / HuggingFace / rule-based fallback
  • Ad Copy Analyzer β€” Sentiment analysis + engagement prediction via HuggingFace NLP
  • Creative Analyzer β€” Image quality scoring via Google Cloud Vision API
  • Budget Optimizer β€” ROAS-weighted allocation across channels

πŸ“ˆ Dashboard

  • 10+ interactive pages β€” Overview, Campaigns, Predict, Explainability, AI Tools, Budget, Segments, Reports, Alerts
  • Dark/Light theme β€” Toggle between sleek dark mode and clean light mode
  • Responsive design β€” Works on desktop and mobile
  • Real-time data β€” Live connection to FastAPI backend
  • Conversion funnel β€” Visual funnel from impressions β†’ clicks β†’ conversions β†’ revenue

πŸ—οΈ Architecture

AdPulse/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ main.py              # FastAPI server (610 lines, 15+ endpoints)
β”‚   β”œβ”€β”€ .env.example          # API key template
β”‚   └── AdPulse-DataSprint/   # Backend sub-module
β”‚
β”œβ”€β”€ frontend/
β”‚   └── dashboard.html        # Single-page dashboard (1447 lines)
β”‚
β”œβ”€β”€ notebook/
β”‚   β”œβ”€β”€ DataSprint_WinningNotebook.ipynb   # Original Jupyter notebook
β”‚   └── datasprint_complete_notebook.py    # Python script version
β”‚
β”œβ”€β”€ artifacts/                # Pre-trained ML models & data
β”‚   β”œβ”€β”€ best_xgb.joblib       # Tuned XGBoost model
β”‚   β”œβ”€β”€ best_lgb.joblib       # Tuned LightGBM model
β”‚   β”œβ”€β”€ shap_explainer.joblib  # SHAP TreeExplainer
β”‚   β”œβ”€β”€ lime_config.joblib     # LIME configuration
β”‚   β”œβ”€β”€ feature_columns.joblib # Feature column list
β”‚   β”œβ”€β”€ model_metrics.joblib   # Evaluation metrics
β”‚   β”œβ”€β”€ shap_data.joblib       # Pre-computed SHAP values
β”‚   β”œβ”€β”€ cluster_model.joblib   # KMeans campaign clusters
β”‚   β”œβ”€β”€ model_meta.json        # Model metadata
β”‚   └── df_clean_full_with_features.csv  # Processed dataset
β”‚
β”œβ”€β”€ digital_media_dataset.csv  # Raw dataset (3000+ campaigns)
β”œβ”€β”€ requirements.txt           # Python dependencies
β”œβ”€β”€ LICENSE                    # MIT License
└── README.md                 # This file

System Flow

graph LR
    A[πŸ“Š CSV Upload] --> B[FastAPI Backend]
    B --> C[Data Cleaning & Feature Engineering]
    C --> D[XGBoost + LightGBM Ensemble]
    D --> E[Revenue Prediction]
    D --> F[SHAP Explainer]
    D --> G[LIME Explainer]
    E --> H[Dashboard UI]
    F --> H
    G --> H
    B --> I[AI Chat - GPT-4o / HuggingFace]
    B --> J[Ad Copy Analyzer - NLP]
    B --> K[Creative Analyzer - Vision API]
    B --> L[Budget Optimizer]
    I --> H
    J --> H
    K --> H
    L --> H
Loading

πŸš€ Quick Start

Prerequisites

  • Python 3.9+
  • pip (Python package manager)

1. Clone the Repository

git clone https://github.com/YOUR_USERNAME/AdPulse.git
cd AdPulse

2. Install Dependencies

# Create virtual environment (recommended)
python -m venv .venv

# Activate it
# Windows:
.venv\Scripts\activate
# macOS/Linux:
source .venv/bin/activate

# Install packages
pip install -r requirements.txt

3. Configure API Keys (Optional)

# Copy the example env file
cp backend/.env.example backend/.env

# Edit with your keys (optional β€” the app works without them)
# - OPENAI_API_KEY    β†’ for GPT-4o-mini chat
# - HF_TOKEN          β†’ for HuggingFace NLP models
# - GOOGLE_APPLICATION_CREDENTIALS β†’ for Vision API

Note: AdPulse works fully without API keys. AI features gracefully fall back to rule-based responses.

4. Start the Server

cd backend
uvicorn main:app --reload --port 8000

5. Open the Dashboard

Navigate to http://localhost:8000 in your browser.

6. Upload Data

Go to the Upload Data page and upload digital_media_dataset.csv to load campaign data.


πŸ“‘ API Reference

Method Endpoint Description
GET /api/health Server health check + model status
POST /api/upload Upload campaign CSV for processing
GET /api/campaigns Retrieve all campaigns with metrics
GET /api/campaigns/summary Aggregated KPI summary
POST /api/predict Predict revenue for given parameters
GET /api/shap/global SHAP global feature importance
POST /api/chat AI campaign analyst (multi-provider)
POST /api/analyze-copy NLP ad copy sentiment analysis
POST /api/analyze-creative Image quality scoring (Vision API)
POST /api/optimize-budget ROAS-weighted budget allocation
GET /api/report/csv Download campaign report as CSV
GET /api/report/company Generate JSON executive report
GET /api/model/info Model metadata and metrics

πŸ“Š Model Performance

Ensemble Results (Test Set)

Model RΒ² Score RMSE MAE MAPE
XGBoost 0.9852 $1,893 $941 11.34%
LightGBM 0.9977 $749 $378 4.53%
Ensemble (55/45) 0.9933 $1,272 $618 6.02%

Hyperparameter Tuning

  • Optimizer: Optuna TPE Sampler
  • XGBoost: 80 trials
  • LightGBM: 60 trials
  • Cross-validation: 5-fold stratified

Top Revenue Drivers (SHAP)

Rank Feature Avg |SHAP| Direction
1 spend_efficiency 0.412 ↑ Revenue
2 conversions 0.338 ↑ Revenue
3 clicks 0.291 ↑ Revenue
4 funnel_velocity 0.254 ↑ Revenue
5 conversion_rate_pct 0.219 ↑ Revenue

πŸ› οΈ Tech Stack

Layer Technology
Backend FastAPI, Uvicorn, Python 3.9+
ML Models XGBoost, LightGBM, scikit-learn
Explainability SHAP (TreeExplainer), LIME (TabularExplainer)
Clustering KMeans (k=4), StandardScaler
Tuning Optuna (TPE Sampler)
AI Chat OpenAI GPT-4o-mini, HuggingFace Mistral-7B
NLP HuggingFace (RoBERTa Sentiment, BART-MNLI)
Vision Google Cloud Vision API
Frontend Vanilla HTML/CSS/JS, Canvas API
Data Pandas, NumPy

πŸ”§ Development

Running in Development Mode

cd backend
uvicorn main:app --reload --port 8000 --log-level info

Re-training Models

To retrain models from scratch, run the notebook:

cd notebook
python datasprint_complete_notebook.py

This will regenerate all artifacts in the artifacts/ directory.

API Documentation

FastAPI provides automatic interactive API docs:


πŸ“‚ Dataset

The project uses a digital media advertising dataset with 3,000+ campaigns across:

  • 6 Channels: Search, Social Media, Display, Email, Video, Affiliate
  • 4 Regions: North America, Europe, Asia-Pacific, Latin America
  • 3 Device Types: Mobile, Desktop, Tablet
  • 40+ Features after engineering (log transforms, ratios, interaction terms)

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License β€” see the LICENSE file for details.


πŸ‘€ Author

Khushee Dengale
GitHub


Built with ❀️ and a lot of β˜•

About

πŸš€ AI-Powered Campaign Intelligence Platform β€” ML revenue prediction, SHAP/LIME explainability, and real-time campaign optimization

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors