Spaces:
Running
Running
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