Skip to content

divyanshmrawal/AI-Click-Predictor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎯 Ad Click Predictor - Full Stack AI Application

Python FastAPI Machine Learning License

A beautiful full-stack web application that predicts whether a user will click on an advertisement based on their demographic and behavioral data. Powered by Machine Learning (Logistic Regression) with a modern, responsive frontend.

🌟 Features

  • AI-Powered Predictions: Uses a trained Logistic Regression model to predict ad click probability
  • Beautiful UI: Modern, gradient-based design with smooth animations
  • Real-time Results: Instant predictions with animated probability bars
  • Responsive Design: Works seamlessly on desktop, tablet, and mobile
  • RESTful API: FastAPI backend with automatic documentation
  • Interactive: User-friendly form with validation and error handling

πŸ“Έ Screenshots

Homepage

Screenshot 2026-01-06 120115

Prediction Results

Screenshot 2026-01-06 120247

πŸ—οΈ Project Structure

AI-Click-Predictor/
β”œβ”€β”€ backend/                    # Backend (FastAPI + ML Model)
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   └── ad_click_model.pkl # Trained ML model
β”‚   β”œβ”€β”€ data/
β”‚   β”‚   └── advertising.csv    # Training dataset
β”‚   β”œβ”€β”€ train.py               # Model training script
β”‚   β”œβ”€β”€ predict.py             # Prediction utility
β”‚   β”œβ”€β”€ app.py                 # FastAPI server
β”‚   β”œβ”€β”€ requirements.txt       # Python dependencies
β”‚   └── README.md              # Backend documentation
β”œβ”€β”€ frontend/                   # Frontend (HTML/CSS/JS)
β”‚   β”œβ”€β”€ index.html             # Main webpage
β”‚   β”œβ”€β”€ style.css              # Styles and animations
β”‚   β”œβ”€β”€ script.js              # API communication logic
β”‚   └── README.md              # Frontend documentation
└── README.md                  # This file

πŸš€ Quick Start

Prerequisites

  • Python 3.8 or higher
  • pip (Python package manager)
  • Modern web browser (Chrome, Firefox, Edge)

Installation & Running

1. Clone the Repository

git clone https://github.com/yourusername/AI-Click-Predictor.git
cd AI-Click-Predictor

2. Start the Backend

cd backend
pip install -r requirements.txt
python -m uvicorn app:app --reload

The backend will start at http://127.0.0.1:8000

3. Open the Frontend

Open frontend/index.html in your web browser:

  • Option 1: Double-click frontend/index.html
  • Option 2: Right-click β†’ Open with β†’ Your Browser
  • Option 3: Use a local server (e.g., Live Server in VS Code)

4. Make a Prediction!

  1. Fill in the form with user information:
    • Age
    • Daily Time Spent on Site (minutes)
    • Area Income ($)
    • Daily Internet Usage (minutes)
    • Gender
  2. Click "Predict Click Probability"
  3. See the AI prediction with probability scores!

πŸ“Š How It Works

Machine Learning Model

The application uses Logistic Regression trained on advertising data with the following features:

Feature Description
Age User's age in years
Daily Time Spent on Site Average time spent on website (minutes)
Area Income Average income of the user's geographical area ($)
Daily Internet Usage Daily internet usage (minutes)
Gender Male (1) or Female (0)

Output: Binary classification (Click = 1, No Click = 0) with probability scores

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      HTTP POST      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      Prediction      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Frontend  β”‚ ──────────────────> β”‚   FastAPI    β”‚ ──────────────────>  β”‚  ML Model   β”‚
β”‚  (Browser)  β”‚                     β”‚   Backend    β”‚                      β”‚  (sklearn)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ <β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ <β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  JSON Response                           Probabilities
  1. User Input: User fills the form on the frontend
  2. API Request: JavaScript sends POST request to /predict endpoint
  3. Model Processing: FastAPI loads the model and makes prediction
  4. Response: Returns prediction + probabilities as JSON
  5. Display: Frontend shows results with animated bars

πŸ› οΈ Technologies Used

Backend

  • Python 3.12 - Programming language
  • FastAPI - Modern web framework for APIs
  • Uvicorn - ASGI server
  • scikit-learn - Machine learning library
  • pandas - Data manipulation
  • joblib - Model serialization

Frontend

  • HTML - Structure
  • CSS - Styling with gradients, animations, and glassmorphism
  • Vanilla JavaScript - API communication and DOM manipulation
  • Google Fonts (Inter) - Modern typography

πŸ“‘ API Documentation

Once the backend is running, visit http://127.0.0.1:8000/docs for interactive API documentation (Swagger UI).

Endpoints

GET /

Check if the API is running.

Response:

{
  "message": "Ad Click Predictor API is running!"
}

POST /predict

Make a prediction based on user data.

Request Body:

{
  "age": 35,
  "daily_time_spent": 60.5,
  "area_income": 65000,
  "daily_internet_usage": 200,
  "male": 1
}

Response:

{
  "prediction": 0,
  "message": "User will NOT click the ad",
  "probability_no_click": 81.96,
  "probability_click": 18.04
}

🎨 UI Features

  • Gradient Backgrounds: Beautiful purple gradient (#667eea β†’ #764ba2)
  • Smooth Animations: Fade-in, slide-up, and bounce effects
  • Interactive Elements: Hover effects on inputs and buttons
  • Progress Bars: Animated probability visualization
  • Responsive Design: Adapts to all screen sizes
  • Error Handling: User-friendly error messages

πŸ§ͺ Testing

Test the Backend

Visit http://127.0.0.1:8000/docs and use the interactive API tester.

Test the Frontend

Use these sample inputs:

Example 1: Will NOT Click

  • Age: 35
  • Daily Time Spent: 60.5
  • Area Income: 65000
  • Daily Internet Usage: 200
  • Gender: Male

Example 2: Will Click

  • Age: 28
  • Daily Time Spent: 80
  • Area Income: 45000
  • Daily Internet Usage: 250
  • Gender: Female

πŸ“ Development Process

This project was built step-by-step:

  1. βœ… Trained Logistic Regression model on advertising data
  2. βœ… Created FastAPI backend with prediction endpoint
  3. βœ… Designed modern, responsive frontend
  4. βœ… Implemented API communication with fetch API
  5. βœ… Added animations and error handling
  6. βœ… Tested end-to-end functionality

🀝 Contributing

Contributions are welcome! Feel free to:

  • Report bugs
  • Suggest new features
  • Submit pull requests

πŸ‘¨β€πŸ’» Author

Divyansh Rawal

⭐ If you found this project helpful, please give it a star! ⭐

About

A full-stack web application that predicts whether a user will click on an advertisement based on their demographic and behavioral data. Powered by Machine Learning (Logistic Regression) with a modern, responsive frontend.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors