File size: 2,551 Bytes
52b0ede 46cc63a 52b0ede 46cc63a 52b0ede 46cc63a 52b0ede | 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 | # Referencia API (FastAPI)
URL base (local): `http://localhost:8000`
Documentación interactiva: `/docs`, `/redoc`
Implementación: [`src/api/main.py`](../src/api/main.py)
---
## Endpoints
| Método | Ruta | Descripción |
|--------|------|-------------|
| `GET` | `/` | Estado del servicio y modelo activo |
| `GET` | `/model-info` | Metadatos del modelo cargado |
| `GET` | `/models` | Modelos disponibles y activo |
| `PUT` | `/model/{model_name}` | Cambiar modelo activo |
| `POST` | `/predict` | Clasificar un comentario |
| `POST` | `/predict-batch` | Hasta 100 comentarios |
| `POST` | `/predict-video` | Comentarios de un vídeo de YouTube |
---
## `POST /predict`
**Cuerpo**
```json
{
"text": "Texto del comentario",
"threshold": 0.5
}
```
**Respuesta**
```json
{
"text": "Texto del comentario",
"is_toxic": false,
"probability": 0.08,
"labels": [],
"model_used": "Meta-Feature Stacking (Production)",
"latency_ms": 15.2
}
```
- `is_toxic`: `true` = **Tóxico**, `false` = **Seguro**
- `probability`: probabilidad de clase tóxica (0–1)
**curl**
```bash
curl -s -X POST http://localhost:8000/predict \
-H "Content-Type: application/json" \
-d '{"text": "¡Gran vídeo, gracias!", "threshold": 0.5}'
```
---
## `POST /predict-batch`
```bash
curl -s -X POST http://localhost:8000/predict-batch \
-H "Content-Type: application/json" \
-d '{"texts": ["Comentario seguro", "Eres un idiota"], "threshold": 0.5}'
```
---
## `POST /predict-video`
Requiere `YOUTUBE_API_KEY` en `.env` para comentarios reales.
```json
{
"url": "https://www.youtube.com/watch?v=VIDEO_ID",
"max_comments": 50,
"threshold": 0.5
}
```
---
## Modelos del demo
[`configs/model_catalog.yaml`](../configs/model_catalog.yaml) · métricas baselines: [`models/baseline/manifest.json`](../models/baseline/manifest.json)
| Nombre | Artefacto / pesos |
|--------|-------------------|
| `Meta-Feature Stacking (Production)` | `models/production_final/meta_stack_final.joblib` |
| `LR + TF-IDF (Baseline)` | `models/baseline/lr_tfidf.joblib` |
| `Frozen Toxic-BERT (Baseline)` | Hugging Face `unitary/toxic-bert` |
```bash
curl -s -X POST http://localhost:8000/models/select \
-H "Content-Type: application/json" \
-d '{"model_name": "LR + TF-IDF (Baseline)"}'
```
---
## Variables de entorno
| Variable | Descripción |
|----------|-------------|
| `MODEL_NAME` | Por defecto: Meta-Feature Stacking (Production) |
| `YOUTUBE_API_KEY` | API de YouTube para `/predict-video` |
Ver [`.env.example`](../.env.example).
|