Spaces:
Sleeping
Sleeping
File size: 6,384 Bytes
7eb5b75 669f7f8 ac7ea7c 7eb5b75 | 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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | # DDA Change Detection β Local Dev Setup
This repo is the **development branch** of the satellite change-detection app (DDA SOW). It runs the full dev UI: image library, GeoTIFF comparison, async jobs, reports, and PDF export.
**Live dev Space (reference):** https://coderuday21-satdetect-dev.hf.space
**Production Space (do not deploy this repo there without review):** https://coderuday21-satdetect.hf.space
---
## 1. Prerequisites
| Requirement | Notes |
|-------------|--------|
| **Python 3.10 β 3.12** | Tested with **3.11** (same as Docker). 3.13+ may have wheel issues for some packages. |
| **Git** | Clone this repository. |
| **~4 GB free disk** | PyTorch (CPU), transformers model cache, and sample GeoTIFFs. |
| **RAM 8 GB+ recommended** | Detection loads AdaptFormer; large GeoTIFFs use more RAM. |
### Windows (GeoTIFF / rasterio)
`rasterio` needs GDAL. Easiest options:
**Option A β pip wheels (try first):**
```powershell
pip install -r requirements.txt
python -c "import rasterio; print('rasterio OK', rasterio.__version__)"
```
**Option B β if rasterio fails, use Conda for GDAL then pip for the rest:**
```powershell
conda create -n dda-cd python=3.11 -y
conda activate dda-cd
conda install -c conda-forge gdal rasterio -y
pip install -r requirements.txt
```
**Option C β OSGeo4W:** Install [OSGeo4W](https://trac.osgeo.org/osgeo4w/) and ensure `gdal` is on `PATH` before `pip install rasterio`.
### macOS / Linux
```bash
# macOS (Homebrew)
brew install gdal
# Ubuntu/Debian
sudo apt-get install gdal-bin libgdal-dev
export GDAL_CONFIG=/usr/bin/gdal-config
pip install -r requirements.txt
```
---
## 2. Clone and install
```bash
git clone https://github.com/Uday-at-Vedang/Change-Detection-DEV.git
cd Change-Detection-DEV
python -m venv venv
```
**Windows:**
```powershell
venv\Scripts\activate
pip install -U pip setuptools wheel
pip install -r requirements.txt
```
**macOS / Linux:**
```bash
source venv/bin/activate
pip install -U pip setuptools wheel
pip install -r requirements.txt
```
> First `pip install` may take 10β20 minutes (PyTorch + transformers).
---
## 3. Environment variables (optional)
Copy the template and edit if needed:
```bash
cp .env.example .env
```
| Variable | Default (local) | Purpose |
|----------|----------------|---------|
| `APP_MODE` | `dda` (set by `run.py`) | `dda` = full dev UI; `legacy` = simple upload UI |
| `SECRET_KEY` | random fallback | Set in production |
| `DATABASE_URL` | SQLite in `data/` | PostgreSQL optional |
| `LOCAL_LIBRARY_ROOT` | `library_sources/` | Custom image library folder |
| `MAX_GEOTIFF_MB` | `5120` | Max GeoTIFF upload size (MB) |
| `DETECTION_MAX_SIDE` | `4096` local / `2048` HF | Max pixel side for detection |
| `EMAIL_API_URL` | manager API | Email notifications |
| `SMTP_USER` / `SMTP_PASS` | β | Use SMTP if API URL empty |
| `PUBLIC_BASE_URL` | `http://localhost:8000` | Report links in emails |
Local dev does **not** require email config unless you test notifications.
---
## 4. Image library (local GeoTIFFs)
Place images under year folders (not committed to git β too large):
```
library_sources/
2024/
site_a.tif
2025/
site_b.tif
2026/
```
See `library_sources/README.md` for details. Supported: `.tif`, `.tiff`, `.png`, `.jpg`.
After adding files, start the app and click **Image Library β Refresh**.
---
## 5. Run the app
```bash
python run.py
```
Opens **http://127.0.0.1:8000** with the DDA dev UI (3 tabs: Image Library, Change Detection, Reports).
Alternative (with auto-reload during development):
```bash
set APP_MODE=dda # Windows
export APP_MODE=dda # macOS/Linux
uvicorn app.main:app --reload --host 127.0.0.1 --port 8000
```
### First run
- Creates `data/satellite_app.db` and `data/overlays/`.
- Downloads **AdaptFormer** model from Hugging Face on first detection (~500 MB). Requires internet.
- Seed data: Delhi zone/village hierarchy is loaded automatically in DDA mode.
### Health check
```bash
curl http://127.0.0.1:8000/health
```
Expected: `"appMode": "dda"`, `"status": "ok"`.
---
## 6. Using the dev UI
1. **Image Library** β scan year folders, upload GeoTIFFs (up to 5 GB), view hierarchy.
2. **Change Detection** β pick Base (T1) and Comparison (T2), run detection (async jobs on HF; sync locally).
3. **Reports** β history, PDF download, browser report at `/dda/reports/{id}`.
4. **Bell icon** β in-app notifications for completed jobs.
5. **Review (FR-08)** β Confirm / False Positive per region, export confirmed CSV, submit to dept API (`DEPT_API_URL`).
6. **Session users** β Each browser gets isolated history via `dda_session_id` cookie (no login required).
7. **Admin** β Optional `DDA_ADMIN_EMAIL` / `DDA_ADMIN_PASSWORD` for admin role; `GET /api/dda/admin/status`.
---
## 7. Project layout (DDA)
```
app/
main.py # FastAPI entry
detection_engine.py # Change detection pipeline
dda/ # DDA modules (library, jobs, reports, geo)
static/js/dda/ # Dev frontend
templates/index_dda.html
docs/IMPLEMENTATION_PLAN_DDA.md # SOW phase plan
```
---
## 8. Troubleshooting
| Issue | Fix |
|-------|-----|
| `ImportError: rasterio` | Install GDAL (see Β§1), then reinstall rasterio |
| Simple upload UI instead of DDA tabs | Set `APP_MODE=dda` or use `python run.py` |
| Library empty | Add `.tif` files under `library_sources/YYYY/` and click Refresh |
| Detection slow / OOM | Lower `DETECTION_MAX_SIDE=2048` or use smaller images |
| Model download fails | Check internet; set `HF_HOME` to a writable folder |
| Port 8000 in use | Change `PORT` in `run.py` or use `--port 8001` with uvicorn |
---
## 9. Deploy to Hugging Face dev Space (maintainers)
See `DEPLOYMENT.md`. Dev Space remote:
```powershell
git remote add hf-dev https://huggingface.co/spaces/coderuday21/satdetect-dev
git push hf-dev master:main
```
Do **not** push `master` to production `satdetect` without explicit sign-off.
---
## 10. Key API endpoints (DDA)
| Method | Path | Description |
|--------|------|-------------|
| GET | `/health` | Health + app mode |
| GET | `/api/dda/local/images` | Library image list |
| POST | `/api/dda/jobs` | Queue async detection |
| GET | `/api/dda/reports/{id}/pdf` | PDF export |
| GET | `/dda/reports/{id}` | Browser report page |
| GET | `/api/history` | Detection run history |
|