Spaces:
Running
Running
File size: 3,269 Bytes
aea087a 1a4e259 aea087a 1a4e259 aea087a 1a4e259 aea087a 1a4e259 aea087a 1a4e259 aea087a 1a4e259 aea087a 1a4e259 aea087a 1a4e259 aea087a 1a4e259 aea087a 1a4e259 aea087a 1a4e259 aea087a 1a4e259 aea087a 1a4e259 aea087a 1a4e259 aea087a 1a4e259 aea087a 1a4e259 aea087a 1a4e259 aea087a 3dee06e aea087a 1a4e259 aea087a 3dee06e aea087a 1a4e259 aea087a 1a4e259 | 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 | # Architecture
## Deployment
```
GitHub (source code)
β
βββΊ Hugging Face Spaces (Docker runtime)
β builds and runs the FastAPI container
β
βββΊ on startup: downloads model from HF Hub
β huggingface.co/cmeneses99/sms-classifier
β (model.safetensors, tokenizer, config β ~520MB)
β
βββΊ serves API on port 7860
https://cmeneses99-sms-classifier-api.hf.space
cron-job.org ββGET /health every 10minβββΊ HF Spaces (keep-alive)
```
## Request flow
```
Client
β
βΌ
FastAPI
β
βββ web/pages.py β HTML responses (/, /classify, /classify/batch, /categories)
βββ api/inference.py β POST /classify, POST /classify/batch
βββ api/meta.py β GET /health, GET /api/categories
β
βΌ
services/classifier.py
β
βββ LRU Cache (core/cache.py) ββhitβββΊ return cached response
β
βββ miss βββΊ core/model_loader.py (HuggingFace pipeline)
βββ distilbert-base-multilingual-cased (fine-tuned)
βββ top_k=3 predictions β PredictResponse
```
## Model
| Detail | Value |
|------------------|--------------------------------------------------------|
| Base model | `distilbert-base-multilingual-cased` |
| Task | Sequence classification |
| Categories | 9 |
| Training data | 3,150 synthetic examples (350/category, ES + EN) |
| Training | 5 epochs, fine-tuned with HuggingFace Trainer API |
| Runtime | CPU-only (PyTorch CPU build) |
| Cache | LRU, max 512 entries, thread-safe |
## Project structure
```
app/
βββ main.py # Lifespan + router registration
βββ utils.py # normalize(), read_static()
βββ core/ # Shared infrastructure
β βββ cache.py # Thread-safe LRU cache
β βββ model_loader.py # Downloads model from HF Hub on startup
β βββ schemas.py # Pydantic v2 request/response models
β βββ category_meta.py # Labels, colors and examples per category
βββ services/
β βββ classifier.py # Inference logic with cache integration
βββ api/ # JSON endpoints
β βββ inference.py # POST /classify, POST /classify/batch
β βββ meta.py # GET /health, GET /api/categories
βββ web/ # HTML endpoints
β βββ pages.py # UI routes
βββ templates/ # HTML files
βββ home.html
βββ index.html # Single classifier UI
βββ batch.html # Batch classifier UI
βββ categories.html
training/
βββ config.py
βββ generate_dataset.py
βββ train.py
βββ eval_report.py
```
|