Spaces:
Sleeping
Sleeping
Commit ·
aea087a
1
Parent(s): d6a2338
Rewrite all docs in English
Browse filesCo-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- ARCHITECTURE.md +41 -41
- README.md +78 -77
- USAGE.md +43 -43
ARCHITECTURE.md
CHANGED
|
@@ -1,79 +1,79 @@
|
|
| 1 |
-
#
|
| 2 |
|
| 3 |
-
##
|
| 4 |
|
| 5 |
```
|
| 6 |
-
GitHub (
|
| 7 |
│
|
| 8 |
-
└─► Hugging Face Spaces (
|
| 9 |
-
│
|
| 10 |
│
|
| 11 |
-
├─►
|
| 12 |
│ huggingface.co/cmeneses99/sms-classifier
|
| 13 |
│ (model.safetensors, tokenizer, config — ~520MB)
|
| 14 |
│
|
| 15 |
-
└─►
|
| 16 |
https://cmeneses99-sms-classifier-api.hf.space
|
| 17 |
|
| 18 |
-
cron-job.org ──GET /health
|
| 19 |
```
|
| 20 |
|
| 21 |
-
##
|
| 22 |
|
| 23 |
```
|
| 24 |
-
|
| 25 |
│
|
| 26 |
▼
|
| 27 |
-
FastAPI
|
| 28 |
│
|
| 29 |
-
├── pages.py →
|
| 30 |
-
├── inference.py → POST /classify, POST /classify/batch
|
| 31 |
-
└── meta.py → GET /health, GET /api/categories
|
| 32 |
│
|
| 33 |
▼
|
| 34 |
services/classifier.py
|
| 35 |
│
|
| 36 |
-
├──
|
| 37 |
│
|
| 38 |
-
└── miss ──► model_loader.py (
|
| 39 |
└── distilbert-base-multilingual-cased (fine-tuned)
|
| 40 |
-
└── top_k=3
|
| 41 |
```
|
| 42 |
|
| 43 |
-
##
|
| 44 |
|
| 45 |
-
|
|
| 46 |
-
|---|---|
|
| 47 |
-
|
|
| 48 |
-
|
|
| 49 |
-
|
|
| 50 |
-
|
|
| 51 |
-
|
|
| 52 |
-
| Runtime
|
| 53 |
-
| Cache
|
| 54 |
|
| 55 |
-
##
|
| 56 |
|
| 57 |
```
|
| 58 |
app/
|
| 59 |
-
├── main.py # Lifespan +
|
| 60 |
├── utils.py # normalize(), read_static()
|
| 61 |
-
├── core/ #
|
| 62 |
-
│ ├── cache.py #
|
| 63 |
-
│ ├── model_loader.py #
|
| 64 |
-
│ ├── schemas.py #
|
| 65 |
-
│ └── category_meta.py # Labels,
|
| 66 |
├── services/
|
| 67 |
-
│ └── classifier.py #
|
| 68 |
-
├── api/ #
|
| 69 |
│ ├── inference.py # POST /classify, POST /classify/batch
|
| 70 |
│ └── meta.py # GET /health, GET /api/categories
|
| 71 |
-
├── web/ #
|
| 72 |
-
│ └── pages.py #
|
| 73 |
-
└── templates/ #
|
| 74 |
├── home.html
|
| 75 |
-
├── index.html #
|
| 76 |
-
├── batch.html #
|
| 77 |
└── categories.html
|
| 78 |
training/
|
| 79 |
├── config.py
|
|
|
|
| 1 |
+
# Architecture
|
| 2 |
|
| 3 |
+
## Deployment
|
| 4 |
|
| 5 |
```
|
| 6 |
+
GitHub (source code)
|
| 7 |
│
|
| 8 |
+
└─► Hugging Face Spaces (Docker runtime)
|
| 9 |
+
│ builds and runs the FastAPI container
|
| 10 |
│
|
| 11 |
+
├─► on startup: downloads model from HF Hub
|
| 12 |
│ huggingface.co/cmeneses99/sms-classifier
|
| 13 |
│ (model.safetensors, tokenizer, config — ~520MB)
|
| 14 |
│
|
| 15 |
+
└─► serves API on port 7860
|
| 16 |
https://cmeneses99-sms-classifier-api.hf.space
|
| 17 |
|
| 18 |
+
cron-job.org ──GET /health every 10min──► HF Spaces (keep-alive)
|
| 19 |
```
|
| 20 |
|
| 21 |
+
## Request flow
|
| 22 |
|
| 23 |
```
|
| 24 |
+
Client
|
| 25 |
│
|
| 26 |
▼
|
| 27 |
+
FastAPI
|
| 28 |
│
|
| 29 |
+
├── web/pages.py → HTML responses (/, /classify, /classify/batch, /categories)
|
| 30 |
+
├── api/inference.py → POST /classify, POST /classify/batch
|
| 31 |
+
└── api/meta.py → GET /health, GET /api/categories
|
| 32 |
│
|
| 33 |
▼
|
| 34 |
services/classifier.py
|
| 35 |
│
|
| 36 |
+
├── LRU Cache (core/cache.py) ──hit──► return cached response
|
| 37 |
│
|
| 38 |
+
└── miss ──► core/model_loader.py (HuggingFace pipeline)
|
| 39 |
└── distilbert-base-multilingual-cased (fine-tuned)
|
| 40 |
+
└── top_k=3 predictions → PredictResponse
|
| 41 |
```
|
| 42 |
|
| 43 |
+
## Model
|
| 44 |
|
| 45 |
+
| Detail | Value |
|
| 46 |
+
|------------------|--------------------------------------------------------|
|
| 47 |
+
| Base model | `distilbert-base-multilingual-cased` |
|
| 48 |
+
| Task | Sequence classification |
|
| 49 |
+
| Categories | 9 |
|
| 50 |
+
| Training data | 3,150 synthetic examples (350/category, ES + EN) |
|
| 51 |
+
| Training | 5 epochs, fine-tuned with HuggingFace Trainer API |
|
| 52 |
+
| Runtime | CPU-only (PyTorch CPU build) |
|
| 53 |
+
| Cache | LRU, max 512 entries, thread-safe |
|
| 54 |
|
| 55 |
+
## Project structure
|
| 56 |
|
| 57 |
```
|
| 58 |
app/
|
| 59 |
+
├── main.py # Lifespan + router registration
|
| 60 |
├── utils.py # normalize(), read_static()
|
| 61 |
+
├── core/ # Shared infrastructure
|
| 62 |
+
│ ├── cache.py # Thread-safe LRU cache
|
| 63 |
+
│ ├── model_loader.py # Downloads model from HF Hub on startup
|
| 64 |
+
│ ├── schemas.py # Pydantic v2 request/response models
|
| 65 |
+
│ └── category_meta.py # Labels, colors and examples per category
|
| 66 |
├── services/
|
| 67 |
+
│ └── classifier.py # Inference logic with cache integration
|
| 68 |
+
├── api/ # JSON endpoints
|
| 69 |
│ ├── inference.py # POST /classify, POST /classify/batch
|
| 70 |
│ └── meta.py # GET /health, GET /api/categories
|
| 71 |
+
├── web/ # HTML endpoints
|
| 72 |
+
│ └── pages.py # UI routes
|
| 73 |
+
└── templates/ # HTML files
|
| 74 |
├── home.html
|
| 75 |
+
├── index.html # Single classifier UI
|
| 76 |
+
├── batch.html # Batch classifier UI
|
| 77 |
└── categories.html
|
| 78 |
training/
|
| 79 |
├── config.py
|
README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
---
|
| 2 |
title: SMS Classifier API
|
| 3 |
emoji: 📱
|
| 4 |
colorFrom: blue
|
|
@@ -10,135 +10,135 @@ pinned: false
|
|
| 10 |
|
| 11 |
# SMS Classifier API
|
| 12 |
|
| 13 |
-
|
| 14 |
|
| 15 |
**Live demo:** https://cmeneses99-sms-classifier-api.hf.space
|
| 16 |
|
| 17 |
-
##
|
| 18 |
|
| 19 |
-
|
|
| 20 |
-
| ---------------------- | ------------------------------------------------- |
|
| 21 |
-
| `transaction` |
|
| 22 |
-
| `otp_verification` |
|
| 23 |
-
| `promotion_offer` |
|
| 24 |
-
| `security_alert` |
|
| 25 |
-
| `delivery_logistics` |
|
| 26 |
-
| `appointment_reminder` |
|
| 27 |
-
| `customer_service` | Tickets,
|
| 28 |
-
| `spam_advertising` |
|
| 29 |
-
| `billing_reminder` |
|
| 30 |
|
| 31 |
-
##
|
| 32 |
|
| 33 |
- **Python 3.11** + **FastAPI** + **Uvicorn**
|
| 34 |
-
- **DistilBERT** (`distilbert-base-multilingual-cased`)
|
| 35 |
-
- **PyTorch** (CPU-only
|
| 36 |
-
- **Pydantic v2**
|
| 37 |
-
- **Docker**
|
| 38 |
-
- **Hugging Face Spaces**
|
| 39 |
-
- **Hugging Face Hub**
|
| 40 |
|
| 41 |
-
##
|
| 42 |
|
| 43 |
```
|
| 44 |
app/
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
training/
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
```
|
| 70 |
|
| 71 |
-
##
|
| 72 |
|
| 73 |
-
###
|
| 74 |
|
| 75 |
- Python 3.11+
|
| 76 |
-
-
|
| 77 |
|
| 78 |
```bash
|
| 79 |
-
#
|
| 80 |
python -m venv .venv
|
| 81 |
.venv\Scripts\activate # Windows
|
| 82 |
source .venv/bin/activate # Linux/Mac
|
| 83 |
|
| 84 |
-
#
|
| 85 |
pip install -r requirements.txt
|
| 86 |
pip install torch --index-url https://download.pytorch.org/whl/cpu
|
| 87 |
|
| 88 |
-
#
|
| 89 |
uvicorn app.main:app --reload
|
| 90 |
```
|
| 91 |
|
| 92 |
-
API
|
| 93 |
|
| 94 |
-
###
|
| 95 |
|
| 96 |
```bash
|
| 97 |
docker compose up --build
|
| 98 |
```
|
| 99 |
|
| 100 |
-
##
|
| 101 |
|
| 102 |
```bash
|
| 103 |
pip install -r requirements-training.txt
|
| 104 |
|
| 105 |
cd training
|
| 106 |
-
python generate_dataset.py #
|
| 107 |
-
python train.py # fine-tuning
|
| 108 |
-
python eval_report.py #
|
| 109 |
```
|
| 110 |
|
| 111 |
## Endpoints
|
| 112 |
|
| 113 |
-
|
|
| 114 |
-
| ------ | ----------------- | ----------------------------------
|
| 115 |
-
| `GET` | `/` | Home
|
| 116 |
-
| `GET` | `/classify` |
|
| 117 |
-
| `GET` | `/classify/batch` |
|
| 118 |
-
| `GET` | `/categories` |
|
| 119 |
-
| `POST` | `/classify` |
|
| 120 |
-
| `POST` | `/classify/batch` |
|
| 121 |
-
| `GET` | `/api/categories` |
|
| 122 |
-
| `GET` | `/health` |
|
| 123 |
|
| 124 |
### POST /classify
|
| 125 |
|
| 126 |
```bash
|
| 127 |
curl -X POST http://localhost:8000/classify \
|
| 128 |
-H "Content-Type: application/json" \
|
| 129 |
-
-d '{"text": "
|
| 130 |
```
|
| 131 |
|
| 132 |
```json
|
| 133 |
{
|
| 134 |
-
"text": "
|
| 135 |
"prediction": {
|
| 136 |
"category": "otp_verification",
|
| 137 |
"confidence": 0.9821
|
| 138 |
},
|
| 139 |
"top_3": [
|
| 140 |
{ "category": "otp_verification", "confidence": 0.9821 },
|
| 141 |
-
{ "category": "security_alert",
|
| 142 |
{ "category": "customer_service", "confidence": 0.0044 }
|
| 143 |
],
|
| 144 |
"cached": false
|
|
@@ -150,7 +150,7 @@ curl -X POST http://localhost:8000/classify \
|
|
| 150 |
```bash
|
| 151 |
curl -X POST http://localhost:8000/classify/batch \
|
| 152 |
-H "Content-Type: application/json" \
|
| 153 |
-
-d '{"texts": ["
|
| 154 |
```
|
| 155 |
|
| 156 |
```json
|
|
@@ -161,15 +161,16 @@ curl -X POST http://localhost:8000/classify/batch \
|
|
| 161 |
}
|
| 162 |
```
|
| 163 |
|
| 164 |
-
##
|
| 165 |
|
| 166 |
-
1.
|
| 167 |
-
2.
|
| 168 |
```bash
|
| 169 |
git remote add hfspace https://USER:TOKEN@huggingface.co/spaces/USER/SPACE-NAME
|
| 170 |
git push hfspace main
|
| 171 |
```
|
| 172 |
-
3. HF Spaces
|
| 173 |
-
4.
|
|
|
|
|
|
|
| 174 |
|
| 175 |
-
El modelo está en [huggingface.co/cmeneses99/sms-classifier](https://huggingface.co/cmeneses99/sms-classifier).
|
|
|
|
| 1 |
+
---
|
| 2 |
title: SMS Classifier API
|
| 3 |
emoji: 📱
|
| 4 |
colorFrom: blue
|
|
|
|
| 10 |
|
| 11 |
# SMS Classifier API
|
| 12 |
|
| 13 |
+
REST API that classifies SMS messages into operational categories using **multilingual DistilBERT** fine-tuned on a synthetic bilingual dataset (ES + EN).
|
| 14 |
|
| 15 |
**Live demo:** https://cmeneses99-sms-classifier-api.hf.space
|
| 16 |
|
| 17 |
+
## Categories
|
| 18 |
|
| 19 |
+
| Category | Description |
|
| 20 |
+
| ---------------------- | ---------------------------------------------------- |
|
| 21 |
+
| `transaction` | Payment confirmations, debits and transfers |
|
| 22 |
+
| `otp_verification` | One-time codes for identity verification |
|
| 23 |
+
| `promotion_offer` | Discounts, coupons and merchant offers |
|
| 24 |
+
| `security_alert` | Unrecognized access and suspicious activity |
|
| 25 |
+
| `delivery_logistics` | Shipment status and order tracking |
|
| 26 |
+
| `appointment_reminder` | Medical and dental appointment reminders |
|
| 27 |
+
| `customer_service` | Tickets, claims and support updates |
|
| 28 |
+
| `spam_advertising` | Fraudulent messages and misleading advertising |
|
| 29 |
+
| `billing_reminder` | Pending invoices and payment due dates |
|
| 30 |
|
| 31 |
+
## Tech stack
|
| 32 |
|
| 33 |
- **Python 3.11** + **FastAPI** + **Uvicorn**
|
| 34 |
+
- **DistilBERT** (`distilbert-base-multilingual-cased`) via HuggingFace Transformers
|
| 35 |
+
- **PyTorch** (CPU-only in production)
|
| 36 |
+
- **Pydantic v2** for validation
|
| 37 |
+
- **Docker** for containerization
|
| 38 |
+
- **Hugging Face Spaces** for deployment
|
| 39 |
+
- **Hugging Face Hub** for model hosting
|
| 40 |
|
| 41 |
+
## Project structure
|
| 42 |
|
| 43 |
```
|
| 44 |
app/
|
| 45 |
+
├── main.py # App entry point
|
| 46 |
+
├── utils.py # normalize(), read_static()
|
| 47 |
+
├── core/ # Shared infrastructure
|
| 48 |
+
│ ├── cache.py # Thread-safe LRU cache
|
| 49 |
+
│ ├── model_loader.py # Downloads and loads the model at startup
|
| 50 |
+
│ ├── schemas.py # Pydantic models
|
| 51 |
+
│ └── category_meta.py # Category metadata
|
| 52 |
+
├── services/
|
| 53 |
+
│ └── classifier.py # Inference logic + LRU cache integration
|
| 54 |
+
├── api/ # JSON endpoints
|
| 55 |
+
│ ├── inference.py # POST /classify, POST /classify/batch
|
| 56 |
+
│ └── meta.py # GET /health, GET /api/categories
|
| 57 |
+
├── web/ # HTML endpoints
|
| 58 |
+
│ └── pages.py # UI routes
|
| 59 |
+
└── templates/ # HTML files
|
| 60 |
+
├── home.html
|
| 61 |
+
├── index.html
|
| 62 |
+
├── batch.html
|
| 63 |
+
└── categories.html
|
| 64 |
training/
|
| 65 |
+
├── config.py # Hyperparameters
|
| 66 |
+
├── generate_dataset.py # Generates training/data/sms_dataset.csv
|
| 67 |
+
├── train.py # Fine-tuning script
|
| 68 |
+
└── eval_report.py # Per-category metrics report
|
| 69 |
```
|
| 70 |
|
| 71 |
+
## Run locally
|
| 72 |
|
| 73 |
+
### Requirements
|
| 74 |
|
| 75 |
- Python 3.11+
|
| 76 |
+
- Trained model in `./model/` (see training section)
|
| 77 |
|
| 78 |
```bash
|
| 79 |
+
# Create virtual environment
|
| 80 |
python -m venv .venv
|
| 81 |
.venv\Scripts\activate # Windows
|
| 82 |
source .venv/bin/activate # Linux/Mac
|
| 83 |
|
| 84 |
+
# Install dependencies
|
| 85 |
pip install -r requirements.txt
|
| 86 |
pip install torch --index-url https://download.pytorch.org/whl/cpu
|
| 87 |
|
| 88 |
+
# Start API
|
| 89 |
uvicorn app.main:app --reload
|
| 90 |
```
|
| 91 |
|
| 92 |
+
API available at `http://localhost:8000`
|
| 93 |
|
| 94 |
+
### With Docker
|
| 95 |
|
| 96 |
```bash
|
| 97 |
docker compose up --build
|
| 98 |
```
|
| 99 |
|
| 100 |
+
## Train the model
|
| 101 |
|
| 102 |
```bash
|
| 103 |
pip install -r requirements-training.txt
|
| 104 |
|
| 105 |
cd training
|
| 106 |
+
python generate_dataset.py # generates training/data/sms_dataset.csv
|
| 107 |
+
python train.py # fine-tuning → saves model to ./model/
|
| 108 |
+
python eval_report.py # per-category metrics report
|
| 109 |
```
|
| 110 |
|
| 111 |
## Endpoints
|
| 112 |
|
| 113 |
+
| Method | Route | Description |
|
| 114 |
+
| ------ | ----------------- | ---------------------------------- |
|
| 115 |
+
| `GET` | `/` | Home with API description |
|
| 116 |
+
| `GET` | `/classify` | Interactive single classifier (UI) |
|
| 117 |
+
| `GET` | `/classify/batch` | Batch classifier (UI) |
|
| 118 |
+
| `GET` | `/categories` | Categories view with examples |
|
| 119 |
+
| `POST` | `/classify` | Classify one message (JSON) |
|
| 120 |
+
| `POST` | `/classify/batch` | Classify multiple messages (JSON) |
|
| 121 |
+
| `GET` | `/api/categories` | List categories (JSON) |
|
| 122 |
+
| `GET` | `/health` | Service status and cache stats |
|
| 123 |
|
| 124 |
### POST /classify
|
| 125 |
|
| 126 |
```bash
|
| 127 |
curl -X POST http://localhost:8000/classify \
|
| 128 |
-H "Content-Type: application/json" \
|
| 129 |
+
-d '{"text": "Your OTP code is 482910. Do not share it."}'
|
| 130 |
```
|
| 131 |
|
| 132 |
```json
|
| 133 |
{
|
| 134 |
+
"text": "Your OTP code is 482910. Do not share it.",
|
| 135 |
"prediction": {
|
| 136 |
"category": "otp_verification",
|
| 137 |
"confidence": 0.9821
|
| 138 |
},
|
| 139 |
"top_3": [
|
| 140 |
{ "category": "otp_verification", "confidence": 0.9821 },
|
| 141 |
+
{ "category": "security_alert", "confidence": 0.0091 },
|
| 142 |
{ "category": "customer_service", "confidence": 0.0044 }
|
| 143 |
],
|
| 144 |
"cached": false
|
|
|
|
| 150 |
```bash
|
| 151 |
curl -X POST http://localhost:8000/classify/batch \
|
| 152 |
-H "Content-Type: application/json" \
|
| 153 |
+
-d '{"texts": ["Your OTP code is 482910.", "Your card was charged $45 at Amazon."]}'
|
| 154 |
```
|
| 155 |
|
| 156 |
```json
|
|
|
|
| 161 |
}
|
| 162 |
```
|
| 163 |
|
| 164 |
+
## Deploy on Hugging Face Spaces
|
| 165 |
|
| 166 |
+
1. Create a Space at [huggingface.co/new-space](https://huggingface.co/new-space) with SDK: **Docker**
|
| 167 |
+
2. Push the code to the Space repo:
|
| 168 |
```bash
|
| 169 |
git remote add hfspace https://USER:TOKEN@huggingface.co/spaces/USER/SPACE-NAME
|
| 170 |
git push hfspace main
|
| 171 |
```
|
| 172 |
+
3. HF Spaces detects the `Dockerfile` automatically and builds the image
|
| 173 |
+
4. On startup, the model is downloaded from HF Hub (~520MB, first time only)
|
| 174 |
+
|
| 175 |
+
Model hosted at [huggingface.co/cmeneses99/sms-classifier](https://huggingface.co/cmeneses99/sms-classifier).
|
| 176 |
|
|
|
USAGE.md
CHANGED
|
@@ -1,54 +1,54 @@
|
|
| 1 |
-
#
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |
---
|
| 6 |
|
| 7 |
-
##
|
| 8 |
|
| 9 |
### Home
|
| 10 |
-
|
| 11 |
|
| 12 |
---
|
| 13 |
|
| 14 |
-
###
|
| 15 |
-
1.
|
| 16 |
-
2.
|
| 17 |
-
3.
|
| 18 |
-
4.
|
| 19 |
-
5.
|
| 20 |
|
| 21 |
---
|
| 22 |
|
| 23 |
-
###
|
| 24 |
-
1.
|
| 25 |
-
2.
|
| 26 |
-
3.
|
| 27 |
-
4.
|
| 28 |
-
5.
|
| 29 |
-
6.
|
| 30 |
|
| 31 |
---
|
| 32 |
|
| 33 |
-
###
|
| 34 |
-
1.
|
| 35 |
-
2.
|
| 36 |
|
| 37 |
---
|
| 38 |
|
| 39 |
-
##
|
| 40 |
|
| 41 |
-
###
|
| 42 |
|
| 43 |
```bash
|
| 44 |
curl -X POST https://cmeneses99-sms-classifier-api.hf.space/classify \
|
| 45 |
-H "Content-Type: application/json" \
|
| 46 |
-
-d '{"text": "
|
| 47 |
```
|
| 48 |
|
| 49 |
```json
|
| 50 |
{
|
| 51 |
-
"text": "
|
| 52 |
"prediction": { "category": "otp_verification", "confidence": 0.9821 },
|
| 53 |
"top_3": [
|
| 54 |
{ "category": "otp_verification", "confidence": 0.9821 },
|
|
@@ -59,18 +59,18 @@ curl -X POST https://cmeneses99-sms-classifier-api.hf.space/classify \
|
|
| 59 |
}
|
| 60 |
```
|
| 61 |
|
| 62 |
-
**
|
| 63 |
|
| 64 |
---
|
| 65 |
|
| 66 |
-
###
|
| 67 |
|
| 68 |
```bash
|
| 69 |
curl -X POST https://cmeneses99-sms-classifier-api.hf.space/classify/batch \
|
| 70 |
-H "Content-Type: application/json" \
|
| 71 |
-d '{
|
| 72 |
"texts": [
|
| 73 |
-
"
|
| 74 |
"Your package will arrive tomorrow between 2-4pm.",
|
| 75 |
"Pay your bill today and avoid penalties."
|
| 76 |
]
|
|
@@ -80,7 +80,7 @@ curl -X POST https://cmeneses99-sms-classifier-api.hf.space/classify/batch \
|
|
| 80 |
```json
|
| 81 |
{
|
| 82 |
"results": [
|
| 83 |
-
{ "text": "
|
| 84 |
{ "text": "Your package will arrive tomorrow...", "prediction": { "category": "delivery_logistics", "confidence": 0.95 }, "top_3": [...], "cached": false },
|
| 85 |
{ "text": "Pay your bill today...", "prediction": { "category": "billing_reminder", "confidence": 0.91 }, "top_3": [...], "cached": false }
|
| 86 |
],
|
|
@@ -89,11 +89,11 @@ curl -X POST https://cmeneses99-sms-classifier-api.hf.space/classify/batch \
|
|
| 89 |
}
|
| 90 |
```
|
| 91 |
|
| 92 |
-
**
|
| 93 |
|
| 94 |
---
|
| 95 |
|
| 96 |
-
###
|
| 97 |
|
| 98 |
```bash
|
| 99 |
curl https://cmeneses99-sms-classifier-api.hf.space/api/categories
|
|
@@ -123,16 +123,16 @@ curl https://cmeneses99-sms-classifier-api.hf.space/health
|
|
| 123 |
|
| 124 |
---
|
| 125 |
|
| 126 |
-
##
|
| 127 |
-
|
| 128 |
-
|
|
| 129 |
-
|---|---|
|
| 130 |
-
| `transaction`
|
| 131 |
-
| `otp_verification`
|
| 132 |
-
| `promotion_offer`
|
| 133 |
-
| `security_alert`
|
| 134 |
-
| `delivery_logistics`
|
| 135 |
-
| `appointment_reminder` | "Recordatorio: cita médica mañana a las 10am"
|
| 136 |
-
| `customer_service`
|
| 137 |
-
| `spam_advertising`
|
| 138 |
-
| `billing_reminder`
|
|
|
|
| 1 |
+
# Usage Guide
|
| 2 |
|
| 3 |
+
Base URL: `https://cmeneses99-sms-classifier-api.hf.space`
|
| 4 |
|
| 5 |
---
|
| 6 |
|
| 7 |
+
## Via Browser (UI)
|
| 8 |
|
| 9 |
### Home
|
| 10 |
+
Open `https://cmeneses99-sms-classifier-api.hf.space` to see a description of the API with all available endpoints and response examples. From there you can navigate to any view using the buttons.
|
| 11 |
|
| 12 |
---
|
| 13 |
|
| 14 |
+
### Classify a single message
|
| 15 |
+
1. Click **"Clasificador Simple"** from the home (or navigate directly to `/classify`)
|
| 16 |
+
2. Type the message in the text field
|
| 17 |
+
3. Click **"Clasificar"** or press **Enter**
|
| 18 |
+
4. The result shows the detected category, confidence score and the top 3 most likely categories
|
| 19 |
+
5. If the same text was already classified before, a **"caché activo"** badge appears
|
| 20 |
|
| 21 |
---
|
| 22 |
|
| 23 |
+
### Classify multiple messages
|
| 24 |
+
1. Click **"Clasificador por Lotes"** from the home (or navigate directly to `/classify/batch`)
|
| 25 |
+
2. Type one message per line in the text area
|
| 26 |
+
3. A real-time counter shows how many messages you have loaded (max 50)
|
| 27 |
+
4. Click **"Clasificar todo"**
|
| 28 |
+
5. Results appear one by one with their category and confidence
|
| 29 |
+
6. The summary bar at the bottom shows how many results came from cache
|
| 30 |
|
| 31 |
---
|
| 32 |
|
| 33 |
+
### Browse available categories
|
| 34 |
+
1. Click **"Categorías"** from the home (or navigate directly to `/categories`)
|
| 35 |
+
2. Each category shows its description and an example in Spanish and English
|
| 36 |
|
| 37 |
---
|
| 38 |
|
| 39 |
+
## Via API (curl)
|
| 40 |
|
| 41 |
+
### Classify one message
|
| 42 |
|
| 43 |
```bash
|
| 44 |
curl -X POST https://cmeneses99-sms-classifier-api.hf.space/classify \
|
| 45 |
-H "Content-Type: application/json" \
|
| 46 |
+
-d '{"text": "Your OTP code is 482910. Do not share it."}'
|
| 47 |
```
|
| 48 |
|
| 49 |
```json
|
| 50 |
{
|
| 51 |
+
"text": "Your OTP code is 482910. Do not share it.",
|
| 52 |
"prediction": { "category": "otp_verification", "confidence": 0.9821 },
|
| 53 |
"top_3": [
|
| 54 |
{ "category": "otp_verification", "confidence": 0.9821 },
|
|
|
|
| 59 |
}
|
| 60 |
```
|
| 61 |
|
| 62 |
+
**Limit:** max 512 characters per message.
|
| 63 |
|
| 64 |
---
|
| 65 |
|
| 66 |
+
### Classify multiple messages
|
| 67 |
|
| 68 |
```bash
|
| 69 |
curl -X POST https://cmeneses99-sms-classifier-api.hf.space/classify/batch \
|
| 70 |
-H "Content-Type: application/json" \
|
| 71 |
-d '{
|
| 72 |
"texts": [
|
| 73 |
+
"Your card was charged $45 at Amazon.",
|
| 74 |
"Your package will arrive tomorrow between 2-4pm.",
|
| 75 |
"Pay your bill today and avoid penalties."
|
| 76 |
]
|
|
|
|
| 80 |
```json
|
| 81 |
{
|
| 82 |
"results": [
|
| 83 |
+
{ "text": "Your card was charged $45 at Amazon.", "prediction": { "category": "transaction", "confidence": 0.97 }, "top_3": [...], "cached": false },
|
| 84 |
{ "text": "Your package will arrive tomorrow...", "prediction": { "category": "delivery_logistics", "confidence": 0.95 }, "top_3": [...], "cached": false },
|
| 85 |
{ "text": "Pay your bill today...", "prediction": { "category": "billing_reminder", "confidence": 0.91 }, "top_3": [...], "cached": false }
|
| 86 |
],
|
|
|
|
| 89 |
}
|
| 90 |
```
|
| 91 |
|
| 92 |
+
**Limit:** max 50 messages per request.
|
| 93 |
|
| 94 |
---
|
| 95 |
|
| 96 |
+
### List categories
|
| 97 |
|
| 98 |
```bash
|
| 99 |
curl https://cmeneses99-sms-classifier-api.hf.space/api/categories
|
|
|
|
| 123 |
|
| 124 |
---
|
| 125 |
|
| 126 |
+
## Categories
|
| 127 |
+
|
| 128 |
+
| Category | Examples |
|
| 129 |
+
|------------------------|-----------------------------------------------------------------------------------|
|
| 130 |
+
| `transaction` | "Your card was charged $45 at Amazon" / "Se debitó $45.000 en Falabella" |
|
| 131 |
+
| `otp_verification` | "Your OTP code is 482910" / "Tu código OTP es 482910" |
|
| 132 |
+
| `promotion_offer` | "Exclusive offer just for you" / "30% de descuento este fin de semana" |
|
| 133 |
+
| `security_alert` | "Failed login attempt detected" / "Acceso no reconocido desde Berlín" |
|
| 134 |
+
| `delivery_logistics` | "Your package will arrive tomorrow" / "Tu pedido está en camino" |
|
| 135 |
+
| `appointment_reminder` | "Dental appointment confirmed" / "Recordatorio: cita médica mañana a las 10am" |
|
| 136 |
+
| `customer_service` | "Your case has been escalated" / "Tu ticket #4821 fue resuelto" |
|
| 137 |
+
| `spam_advertising` | "You have been selected for a reward" / "Ganaste un premio, haz clic aquí" |
|
| 138 |
+
| `billing_reminder` | "Pay your bill today and avoid penalties" / "Tu factura vence el 15 de mayo" |
|