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.
- 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
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
- Python 3.8 or higher
- pip (Python package manager)
- Modern web browser (Chrome, Firefox, Edge)
git clone https://github.com/yourusername/AI-Click-Predictor.git
cd AI-Click-Predictorcd backend
pip install -r requirements.txt
python -m uvicorn app:app --reloadThe backend will start at http://127.0.0.1:8000
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)
- Fill in the form with user information:
- Age
- Daily Time Spent on Site (minutes)
- Area Income ($)
- Daily Internet Usage (minutes)
- Gender
- Click "Predict Click Probability"
- See the AI prediction with probability scores!
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
βββββββββββββββ HTTP POST ββββββββββββββββ Prediction βββββββββββββββ
β Frontend β ββββββββββββββββββ> β FastAPI β ββββββββββββββββββ> β ML Model β
β (Browser) β β Backend β β (sklearn) β
βββββββββββββββ <βββββββββββββββββββ ββββββββββββββββ <βββββββββββββββββββ βββββββββββββββ
JSON Response Probabilities
- User Input: User fills the form on the frontend
- API Request: JavaScript sends POST request to
/predictendpoint - Model Processing: FastAPI loads the model and makes prediction
- Response: Returns prediction + probabilities as JSON
- Display: Frontend shows results with animated bars
- 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
- HTML - Structure
- CSS - Styling with gradients, animations, and glassmorphism
- Vanilla JavaScript - API communication and DOM manipulation
- Google Fonts (Inter) - Modern typography
Once the backend is running, visit http://127.0.0.1:8000/docs for interactive API documentation (Swagger UI).
Check if the API is running.
Response:
{
"message": "Ad Click Predictor API is running!"
}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
}- 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
Visit http://127.0.0.1:8000/docs and use the interactive API tester.
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
This project was built step-by-step:
- β Trained Logistic Regression model on advertising data
- β Created FastAPI backend with prediction endpoint
- β Designed modern, responsive frontend
- β Implemented API communication with fetch API
- β Added animations and error handling
- β Tested end-to-end functionality
Contributions are welcome! Feel free to:
- Report bugs
- Suggest new features
- Submit pull requests
Divyansh Rawal
β If you found this project helpful, please give it a star! β