coderuday21 commited on
Commit
717d61b
·
1 Parent(s): 454d6d6

HF fix: uvicorn-only CMD, defensive mkdir, remove unused numpy, overlay mkdir on save, README troubleshooting

Browse files
Files changed (4) hide show
  1. Dockerfile +2 -1
  2. README.md +7 -0
  3. app/database.py +4 -1
  4. app/main.py +8 -2
Dockerfile CHANGED
@@ -31,4 +31,5 @@ USER appuser
31
  ENV PORT=7860
32
  EXPOSE 7860
33
 
34
- CMD ["sh", "-c", "gunicorn app.main:app -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:${PORT} --workers 1 --timeout 120"]
 
 
31
  ENV PORT=7860
32
  EXPOSE 7860
33
 
34
+ # Single process: uvicorn only (simpler for HF Spaces; avoid gunicorn restart issues)
35
+ CMD ["sh", "-c", "exec uvicorn app.main:app --host 0.0.0.0 --port ${PORT}"]
README.md CHANGED
@@ -84,3 +84,10 @@ change_detection_webapp/
84
  - `POST /api/detect` — form: `before`, `after` (files), `method`, `title`, etc. → returns stats, regions, overlay base64
85
  - `GET /api/history` — list of current user’s runs
86
  - `GET /api/overlay/<path>` — serve saved overlay image
 
 
 
 
 
 
 
 
84
  - `POST /api/detect` — form: `before`, `after` (files), `method`, `title`, etc. → returns stats, regions, overlay base64
85
  - `GET /api/history` — list of current user’s runs
86
  - `GET /api/overlay/<path>` — serve saved overlay image
87
+ - `GET /health` — lightweight health check (no DB)
88
+
89
+ ## Hugging Face: Space stuck on “Restarting”
90
+
91
+ 1. Open your Space → **Settings** → under **Build**, click **Clear build cache** → Save. Then trigger a rebuild (push a commit or click **Restart**).
92
+ 2. Check **Logs** (Build logs + App logs) for Python errors or “Killed” (out of memory).
93
+ 3. In **Settings** → **Hardware**, try a slightly larger CPU/memory if available.
app/database.py CHANGED
@@ -10,7 +10,10 @@ BASE_DIR = Path(__file__).resolve().parent
10
  _home_data = Path.home() / "data"
11
  _local_data = BASE_DIR.parent / "data"
12
  DATA_DIR = _home_data if os.environ.get("SPACE_ID") else _local_data
13
- DATA_DIR.mkdir(parents=True, exist_ok=True)
 
 
 
14
 
15
  DB_PATH = DATA_DIR / "satellite_app.db"
16
 
 
10
  _home_data = Path.home() / "data"
11
  _local_data = BASE_DIR.parent / "data"
12
  DATA_DIR = _home_data if os.environ.get("SPACE_ID") else _local_data
13
+ try:
14
+ DATA_DIR.mkdir(parents=True, exist_ok=True)
15
+ except Exception:
16
+ pass # avoid crashing if read-only or permission issue (e.g. some HF environments)
17
 
18
  DB_PATH = DATA_DIR / "satellite_app.db"
19
 
app/main.py CHANGED
@@ -6,7 +6,6 @@ import uuid
6
  from pathlib import Path
7
  from typing import Optional
8
 
9
- import numpy as np
10
  from sqlalchemy import text as sa_text
11
  from fastapi import FastAPI, Depends, File, Form, HTTPException, Request, UploadFile
12
  from fastapi.responses import FileResponse, HTMLResponse, JSONResponse
@@ -61,7 +60,10 @@ def health():
61
  STATIC_DIR = Path(__file__).resolve().parent.parent / "static"
62
  TEMPLATES_DIR = Path(__file__).resolve().parent.parent / "templates"
63
  OVERLAYS_DIR = DATA_DIR / "overlays"
64
- OVERLAYS_DIR.mkdir(parents=True, exist_ok=True)
 
 
 
65
  THUMB_MAX_SIZE = 200 # max width or height for history thumbnails
66
 
67
  if STATIC_DIR.exists():
@@ -227,6 +229,10 @@ async def detect(
227
  base_name = f"{user.id}_{uuid.uuid4().hex}"
228
  overlay_filename = base_name + ".png"
229
  overlay_path = OVERLAYS_DIR / overlay_filename
 
 
 
 
230
  Image.fromarray(result_image).save(overlay_path)
231
  relative_overlay = f"overlays/{overlay_filename}"
232
 
 
6
  from pathlib import Path
7
  from typing import Optional
8
 
 
9
  from sqlalchemy import text as sa_text
10
  from fastapi import FastAPI, Depends, File, Form, HTTPException, Request, UploadFile
11
  from fastapi.responses import FileResponse, HTMLResponse, JSONResponse
 
60
  STATIC_DIR = Path(__file__).resolve().parent.parent / "static"
61
  TEMPLATES_DIR = Path(__file__).resolve().parent.parent / "templates"
62
  OVERLAYS_DIR = DATA_DIR / "overlays"
63
+ try:
64
+ OVERLAYS_DIR.mkdir(parents=True, exist_ok=True)
65
+ except Exception:
66
+ pass
67
  THUMB_MAX_SIZE = 200 # max width or height for history thumbnails
68
 
69
  if STATIC_DIR.exists():
 
229
  base_name = f"{user.id}_{uuid.uuid4().hex}"
230
  overlay_filename = base_name + ".png"
231
  overlay_path = OVERLAYS_DIR / overlay_filename
232
+ try:
233
+ overlay_path.parent.mkdir(parents=True, exist_ok=True)
234
+ except Exception:
235
+ pass
236
  Image.fromarray(result_image).save(overlay_path)
237
  relative_overlay = f"overlays/{overlay_filename}"
238