File size: 4,499 Bytes
20e1b5d
3d4e00e
20e1b5d
 
1f893f3
20e1b5d
 
 
 
401aaf2
 
 
 
 
 
 
 
 
5cee5a6
4e9c6ba
401aaf2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6383573
401aaf2
5cee5a6
 
 
 
 
 
4e9c6ba
 
 
 
 
401aaf2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
717d61b
 
 
 
 
 
 
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
---
title: AI Change Detection
emoji: πŸ›°οΈ
colorFrom: gray
colorTo: green
sdk: docker
app_port: 7860
---

# Satellite Change Detection β€” Standalone Web App

Standalone web application for satellite image change detection with **user accounts**, **database storage**, and a **clean, modern UI**.

## Features

- **Login / Register** β€” JWT-based auth, passwords hashed with bcrypt
- **Database** β€” SQLite (or set `DATABASE_URL` for PostgreSQL); stores users and detection runs
- **Change detection** β€” Same model as the original app: AI-based, image difference, feature-based, hybrid
- **Detection menu** β€” Choose between General Change Detection and Landslide Detection (Uttarakhand starter)
- **Pothole detection** β€” Separate detection type for road damage (starter pipeline + future model hook)
- **Object classification** β€” Changed regions labeled as Water, Vegetation/Tree, Building, Road, Bare Ground/Soil
- **History** β€” List of past runs with overlay images and stats
- **UI** β€” Single-page app with a dark, β€œcontrol room” style and teal accents

## Setup

1. **Create a virtual environment (recommended)**

   ```bash
   cd change_detection_webapp
   python -m venv venv
   source venv/bin/activate   # Windows: venv\Scripts\activate
   ```

2. **Install dependencies**

   ```bash
   pip install -r requirements.txt
   ```

3. **Run the app**

   ```bash
   uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
   ```

4. Open **http://localhost:8000** in your browser.

## First run

- The SQLite DB and `data/` (overlay images) are created automatically on first use.
- Register a new account from the welcome screen, then sign in.
- Upload **Before** and **After** images, choose a method, and click **Run detection**.
- Results appear below; runs are saved in **History**.

## Configuration

- **Database**: set `DATABASE_URL` (e.g. `postgresql://user:pass@host/db`) to use another DB; otherwise SQLite under `data/satellite_app.db` is used.
- **JWT**: set `SECRET_KEY` in `app/auth.py` (or via env) in production.
- **Email**: By default, notifications are sent via the manager's email API (`https://emailservice.managemybusinessess.com/api/email/send`). Override with `EMAIL_API_URL` if needed. To use SMTP (e.g. Gmail) instead, set `EMAIL_API_URL` to empty and set `SMTP_USER` and `SMTP_PASS`.

- **Landslide module**:
  - Integrated at runtime through the same `/api/detect` endpoint using `detection_type=landslide_detection`.
  - Engine code: `app/landslide_engine.py`
  - Dataset preprocessing starter: `app/landslide_preprocessing.py`
  - Planning/research brief: `Landslide_Detection_Uttarakhand_Integration_Plan.md`

- **Pothole module**:
  - Integrated at runtime through the same `/api/detect` endpoint using `detection_type=pothole_detection`.
  - Engine code: `app/pothole_engine.py`
  - Planning/research brief: `Pothole_Detection_Integration_Plan.md`

## Project layout

```
change_detection_webapp/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ main.py           # FastAPI app, routes
β”‚   β”œβ”€β”€ database.py       # SQLAlchemy, session
β”‚   β”œβ”€β”€ models.py         # User, DetectionRun
β”‚   β”œβ”€β”€ auth.py           # JWT, password hashing
β”‚   └── detection_engine.py  # Change detection (no Streamlit)
β”œβ”€β”€ static/
β”‚   β”œβ”€β”€ css/style.css     # Styles
β”‚   └── js/app.js         # Frontend logic
β”œβ”€β”€ templates/
β”‚   └── index.html        # Single-page UI
β”œβ”€β”€ data/                 # Created at runtime (DB + overlays)
β”œβ”€β”€ requirements.txt
└── README.md
```

## API (for integration)

- `POST /api/auth/register` β€” body: `{ "email", "password", "full_name" }`
- `POST /api/auth/login` β€” body: `{ "email", "password" }` β†’ returns `access_token`
- `GET /api/me` β€” header: `Authorization: Bearer <token>`
- `POST /api/detect` β€” form: `before`, `after` (files), `method`, `title`, etc. β†’ returns stats, regions, overlay base64
- `GET /api/history` β€” list of current user’s runs
- `GET /api/overlay/<path>` β€” serve saved overlay image
- `GET /health` β€” lightweight health check (no DB)

## Hugging Face: Space stuck on β€œRestarting”

1. Open your Space β†’ **Settings** β†’ under **Build**, click **Clear build cache** β†’ Save. Then trigger a rebuild (push a commit or click **Restart**).
2. Check **Logs** (Build logs + App logs) for Python errors or β€œKilled” (out of memory).
3. In **Settings** β†’ **Hardware**, try a slightly larger CPU/memory if available.