Spaces:
Sleeping
Sleeping
metadata
title: Cookie Classifier API
emoji: πͺ
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
license: mit
πͺ Cookie Classifier API
FREE Serverless API for classifying web cookies into privacy categories.
π― What It Does
Classifies cookie names into 4 privacy categories:
- Strictly Necessary - Essential for website functionality
- Functionality - Enhance user experience
- Analytics - Track website usage and performance
- Advertising/Tracking - Marketing and ad targeting
π API Endpoints
Base URL
https://aqibtahir-cookie-classifier-api.hf.space
1. Health Check
GET /
Response:
{
"status": "online",
"model": "Cookie Classifier - Linear Regression",
"categories": ["Strictly Necessary", "Functionality", "Analytics", "Advertising/Tracking"]
}
2. Single Prediction
POST /predict
Content-Type: application/json
{
"cookie_name": "_ga"
}
Response:
{
"cookie_name": "_ga",
"category": "Analytics",
"class_id": 2,
"confidence": 0.89
}
3. Batch Prediction
POST /predict/batch
Content-Type: application/json
{
"cookie_names": ["_ga", "sessionid", "utm_campaign", "doubleclick"]
}
Response:
{
"predictions": [
{
"cookie_name": "_ga",
"category": "Analytics",
"class_id": 2,
"confidence": 0.89
},
{
"cookie_name": "sessionid",
"category": "Strictly Necessary",
"class_id": 0,
"confidence": 0.95
},
...
]
}
π» Usage Examples
JavaScript/Frontend
// Single prediction
async function classifyCookie(cookieName) {
const response = await fetch('https://aqibtahir-cookie-classifier-api.hf.space/predict', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ cookie_name: cookieName })
});
const data = await response.json();
console.log(data.category); // "Analytics"
return data;
}
// Batch prediction
async function classifyManyCookies(cookieNames) {
const response = await fetch('https://aqibtahir-cookie-classifier-api.hf.space/predict/batch', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ cookie_names: cookieNames })
});
const data = await response.json();
return data.predictions;
}
// Usage
classifyCookie('_ga').then(result => {
console.log(`${result.cookie_name} is ${result.category}`);
});
Python
import requests
# Single prediction
response = requests.post(
'https://aqibtahir-cookie-classifier-api.hf.space/predict',
json={'cookie_name': '_ga'}
)
print(response.json())
# Batch prediction
response = requests.post(
'https://aqibtahir-cookie-classifier-api.hf.space/predict/batch',
json={'cookie_names': ['_ga', 'sessionid', 'utm_campaign']}
)
print(response.json())
cURL
# Single prediction
curl -X POST "https://aqibtahir-cookie-classifier-api.hf.space/predict" \
-H "Content-Type: application/json" \
-d '{"cookie_name": "_ga"}'
# Batch prediction
curl -X POST "https://aqibtahir-cookie-classifier-api.hf.space/predict/batch" \
-H "Content-Type: application/json" \
-d '{"cookie_names": ["_ga", "sessionid", "utm_campaign"]}'
π Model Information
- Model: Linear Regression with TF-IDF + Name Features
- Accuracy: 90%
- Training Data: 28,671 cookie samples
- Features:
- TF-IDF word n-grams (1-2)
- TF-IDF char n-grams (3-5)
- Engineered name features (length, patterns, tracker tokens, etc.)
π CORS & Security
- β CORS enabled for all origins (frontend-friendly)
- β No authentication required for public use
- β Rate-limited by Hugging Face Spaces (fair usage)
π Interactive Documentation
Visit the API documentation at:
https://aqibtahir-cookie-classifier-api.hf.space/docs
ποΈ Deployment
This API is deployed on Hugging Face Spaces (FREE tier) and runs 24/7.
Cold Start
- First request may take 10-30 seconds (model loading)
- Subsequent requests are fast (~100-500ms)
π€ Support
For issues or questions:
- Model Repository: aqibtahir/cookie-classifier-lr-tfidf
- Create an issue on the Space
π License
MIT License - Free to use for commercial and non-commercial purposes