File size: 3,154 Bytes
8dff220
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
title: MP Dengue EWS API
emoji: 🦟
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
app_port: 7860
---

# EWS inference API (FastAPI + bundled sklearn / XGB / LGBM / CatBoost)

This `README.md` **must stay at the repository root** of your Hugging Face **Docker** Space (the YAML block above configures the Space card).

## Quick links (when the Space is running)

- **Swagger UI:** `/docs`
- **OpenAPI JSON:** `/openapi.json`
- **Health:** `GET /health`
- **Feature schema:** `GET /schema`
- **Predict:** `POST /predict`

---

## A β€” One-time: build the bundle (your laptop)

From the **parent** project folder (`EWS Dashboard`), with your venv activated:

```bash
python bundle_ews_pipeline.py
```

That writes **`ews_pipeline_bundle.joblib`** into this **`hf_api/`** folder.

---

## B β€” Option 1: Push this `hf_api` folder as the Space repo

1. **Install [Git LFS](https://git-lfs.com)** (`git lfs install` once per machine).

2. On [huggingface.co/new-space](https://huggingface.co/new-space) create a Space:
   - **SDK:** Docker  
   - **Visibility:** Public or Private  
   - **Hardware:** CPU basic (upgrade only if builds are slow)

3. **Do not** add files in the web editor β€” you will push from git.

4. In PowerShell, from **`hf_api/`**:

   ```powershell
   .\prepare_hf_push.ps1
   git remote add origin https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
   git branch -M main
   git commit -m "Initial EWS API + LFS bundle"
   git push -u origin main
   ```

   Use the **HTTPS** clone URL from the Space **Files and versions** tab (it looks like `https://huggingface.co/spaces/...`).

5. Wait for the **Build** log on the Space page. When it is green, open:
   - `https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/docs`

---

## B β€” Option 2: Export a clean folder (no monorepo clutter)

From **`EWS Dashboard`** root:

```bash
python bundle_ews_pipeline.py
python hf_api/export_for_hf_space.py
```

This creates **`ews_hf_space_export/`** next to `hf_api/`. `cd` into it, then `git init`, LFS, `git remote add`, commit, push β€” same as step B4.

---

## C β€” Test `POST /predict`

Minimal body (21 zeros β€” sanity check):

```json
{
  "values": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  "population": 2500000
}
```

Or named features (missing keys default to `0`); optional `population` for `estimated_cases` / `risk_tier`:

```json
{
  "features": { "ir_lag12": 0.5, "precipitation_lag11": 10.0 },
  "population": 2000000
}
```

---

## What is inside the bundle?

- `pipeline_config.json` content (in `config`)
- `scaler`, stage-1 classifier, **non-LSTM** stage-2 regressors, meta-learner  
- LSTM is **not** included (TensorFlow-free image; LSTM slot uses the mean of other regressors in inference code).

---

## Troubleshooting

| Issue | What to do |
|--------|------------|
| Build: `COPY ews_pipeline_bundle.joblib` failed | Run `bundle_ews_pipeline.py` and ensure the joblib is committed and pushed (with **Git LFS**). |
| Push: large file rejected | Run `git lfs install` and `git lfs track "*.joblib"` before committing. |
| 404 on `/` | Open `/docs` β€” or use `/` (redirects to `/docs`). |