GitHub Actions commited on
Commit
98cfcc1
·
1 Parent(s): 6e79243

deploy: sync from GitHub 79ac8fe19fc8dfed0d591248889355a9bd69f532

Browse files
Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -33,14 +33,12 @@ log = logging.getLogger('werkzeug')
33
  log.setLevel(logging.ERROR)
34
 
35
  APP_ROOT = Path(__file__).parent
36
- # On HF Spaces, the app filesystem overlay makes app-root dirs unreliable across requests.
37
- # Use /tmp (RAM-backed tmpfs, always writable) when running on HF Spaces.
38
- # Locally, use app root so files persist across container restarts.
39
- _ON_HF_SPACES = os.environ.get('SPACE_ID') is not None
40
- _data_root = Path('/tmp/nemaquant') if _ON_HF_SPACES else APP_ROOT
41
- UPLOAD_FOLDER = _data_root / 'uploads'
42
- RESULTS_FOLDER = _data_root / 'results'
43
- ANNOT_FOLDER = _data_root / 'annotated'
44
  WEIGHTS_FILE = APP_ROOT / 'weights.pt'
45
  app.config['UPLOAD_FOLDER'] = str(UPLOAD_FOLDER)
46
  app.config['RESULTS_FOLDER'] = str(RESULTS_FOLDER)
@@ -48,11 +46,11 @@ app.config['ANNOT_FOLDER'] = str(ANNOT_FOLDER)
48
  app.config['WEIGHTS_FILE'] = str(WEIGHTS_FILE)
49
  app.config['ALLOWED_EXTENSIONS'] = {'png', 'jpg', 'jpeg', 'tif', 'tiff'}
50
 
51
- # Create dirs at startup
52
  UPLOAD_FOLDER.mkdir(parents=True, exist_ok=True)
53
  RESULTS_FOLDER.mkdir(parents=True, exist_ok=True)
54
  ANNOT_FOLDER.mkdir(parents=True, exist_ok=True)
55
- print(f"Running on HF Spaces: {_ON_HF_SPACES} | Data root: {_data_root}")
56
 
57
  # Load model once at startup, use CUDA if available
58
  MODEL_DEVICE = 'cuda' if cuda.is_available() else 'cpu'
 
33
  log.setLevel(logging.ERROR)
34
 
35
  APP_ROOT = Path(__file__).parent
36
+ # Use /tmp for runtime data works reliably on all container platforms.
37
+ # /tmp is RAM-backed tmpfs, always writable, avoids overlay filesystem issues on HF Spaces.
38
+ # Note: /tmp is cleared on container restart (uploads/results are transient by design).
39
+ UPLOAD_FOLDER = Path('/tmp/nemaquant/uploads')
40
+ RESULTS_FOLDER = Path('/tmp/nemaquant/results')
41
+ ANNOT_FOLDER = Path('/tmp/nemaquant/annotated')
 
 
42
  WEIGHTS_FILE = APP_ROOT / 'weights.pt'
43
  app.config['UPLOAD_FOLDER'] = str(UPLOAD_FOLDER)
44
  app.config['RESULTS_FOLDER'] = str(RESULTS_FOLDER)
 
46
  app.config['WEIGHTS_FILE'] = str(WEIGHTS_FILE)
47
  app.config['ALLOWED_EXTENSIONS'] = {'png', 'jpg', 'jpeg', 'tif', 'tiff'}
48
 
49
+ # Create dirs at startup
50
  UPLOAD_FOLDER.mkdir(parents=True, exist_ok=True)
51
  RESULTS_FOLDER.mkdir(parents=True, exist_ok=True)
52
  ANNOT_FOLDER.mkdir(parents=True, exist_ok=True)
53
+ print(f"Data root: /tmp/nemaquant | Weights: {WEIGHTS_FILE}")
54
 
55
  # Load model once at startup, use CUDA if available
56
  MODEL_DEVICE = 'cuda' if cuda.is_available() else 'cpu'