Spaces:
Sleeping
Sleeping
File size: 4,651 Bytes
31b1043 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | ---
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
```http
GET /
```
**Response:**
```json
{
"status": "online",
"model": "Cookie Classifier - Linear Regression",
"categories": ["Strictly Necessary", "Functionality", "Analytics", "Advertising/Tracking"]
}
```
### 2. Single Prediction
```http
POST /predict
Content-Type: application/json
{
"cookie_name": "_ga"
}
```
**Response:**
```json
{
"cookie_name": "_ga",
"category": "Analytics",
"class_id": 2,
"confidence": 0.89
}
```
### 3. Batch Prediction
```http
POST /predict/batch
Content-Type: application/json
{
"cookie_names": ["_ga", "sessionid", "utm_campaign", "doubleclick"]
}
```
**Response:**
```json
{
"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
```javascript
// 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
```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
```bash
# 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](https://huggingface.co/aqibtahir/cookie-classifier-lr-tfidf)
- Create an issue on the Space
## π License
MIT License - Free to use for commercial and non-commercial purposes
|