sachinchandrankallar commited on
Commit
1aff96b
·
1 Parent(s): f2dfcb8
Files changed (2) hide show
  1. Dockerfile +4 -0
  2. ai_med_extract/app.py +16 -4
Dockerfile CHANGED
@@ -114,6 +114,10 @@ ENV HF_HOME=/tmp/huggingface \
114
  PYTHONUNBUFFERED=1 \
115
  PYTHONPATH=/app
116
 
 
 
 
 
117
  EXPOSE 7860
118
 
119
  CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "1", "--threads", "8", "--timeout", "0", "ai_med_extract.app:app"]
 
114
  PYTHONUNBUFFERED=1 \
115
  PYTHONPATH=/app
116
 
117
+ # Ensure writable directories exist (works on Spaces read-only root)
118
+ RUN mkdir -p /tmp/uploads /tmp/huggingface /tmp/torch /tmp/whisper && \
119
+ chmod -R 777 /tmp
120
+
121
  EXPOSE 7860
122
 
123
  CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "1", "--threads", "8", "--timeout", "0", "ai_med_extract.app:app"]
ai_med_extract/app.py CHANGED
@@ -30,10 +30,22 @@ logging.basicConfig(
30
  app = Flask(__name__)
31
  CORS(app)
32
 
33
- # Configure upload directory
34
- UPLOAD_DIR = '/data/uploads'
35
- os.makedirs(UPLOAD_DIR, exist_ok=True)
36
- app.config['UPLOAD_FOLDER'] = UPLOAD_DIR
 
 
 
 
 
 
 
 
 
 
 
 
37
  app.config['MAX_CONTENT_LENGTH'] = 100 * 1024 * 1024 # 100 MB max file size
38
 
39
  # Set cache directories
 
30
  app = Flask(__name__)
31
  CORS(app)
32
 
33
+ # Configure upload directory with safe fallbacks (avoid creating /data at import time)
34
+ def _resolve_upload_dir() -> str:
35
+ try:
36
+ # Prefer /data/uploads if it already exists and is writable
37
+ data_dir = '/data/uploads'
38
+ if os.path.isdir('/data') and (os.path.isdir(data_dir) or os.access('/data', os.W_OK)):
39
+ os.makedirs(data_dir, exist_ok=True)
40
+ return data_dir
41
+ except Exception:
42
+ pass
43
+ # Fallback to /tmp/uploads which is always writable on Spaces
44
+ tmp_dir = '/tmp/uploads'
45
+ os.makedirs(tmp_dir, exist_ok=True)
46
+ return tmp_dir
47
+
48
+ app.config['UPLOAD_FOLDER'] = _resolve_upload_dir()
49
  app.config['MAX_CONTENT_LENGTH'] = 100 * 1024 * 1024 # 100 MB max file size
50
 
51
  # Set cache directories