GitHub Actions commited on
Commit
aefa161
·
1 Parent(s): 170ef84

deploy: sync from GitHub 4710d63a980234606d7beba5049320b361de63f3

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -33,9 +33,14 @@ log = logging.getLogger('werkzeug')
33
  log.setLevel(logging.ERROR)
34
 
35
  APP_ROOT = Path(__file__).parent
36
- UPLOAD_FOLDER = APP_ROOT / 'uploads'
37
- RESULTS_FOLDER = APP_ROOT / 'results'
38
- ANNOT_FOLDER = APP_ROOT / 'annotated'
 
 
 
 
 
39
  WEIGHTS_FILE = APP_ROOT / 'weights.pt'
40
  app.config['UPLOAD_FOLDER'] = str(UPLOAD_FOLDER)
41
  app.config['RESULTS_FOLDER'] = str(RESULTS_FOLDER)
@@ -43,10 +48,11 @@ app.config['ANNOT_FOLDER'] = str(ANNOT_FOLDER)
43
  app.config['WEIGHTS_FILE'] = str(WEIGHTS_FILE)
44
  app.config['ALLOWED_EXTENSIONS'] = {'png', 'jpg', 'jpeg', 'tif', 'tiff'}
45
 
46
- # Create dirs at startup in case the container filesystem overlays the image build dirs
47
  UPLOAD_FOLDER.mkdir(parents=True, exist_ok=True)
48
  RESULTS_FOLDER.mkdir(parents=True, exist_ok=True)
49
  ANNOT_FOLDER.mkdir(parents=True, exist_ok=True)
 
50
 
51
  # Load model once at startup, use CUDA if available
52
  MODEL_DEVICE = 'cuda' if cuda.is_available() else 'cpu'
 
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
  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'