malavikapradeep2001 commited on
Commit
a2da2f3
·
unverified ·
1 Parent(s): fe38991

Update backend/app.py

Browse files
Files changed (1) hide show
  1. backend/app.py +8 -1
backend/app.py CHANGED
@@ -226,7 +226,8 @@ app.add_middleware(
226
  expose_headers=["*"] # Allow access to response headers
227
  )
228
 
229
- OUTPUT_DIR = "outputs"
 
230
  os.makedirs(OUTPUT_DIR, exist_ok=True)
231
 
232
  # Create image outputs dir
@@ -1000,6 +1001,12 @@ def health():
1000
 
1001
  # Serve frontend only if it has been built; avoid startup failure when dist/ is missing.
1002
  FRONTEND_DIST = os.path.abspath(os.path.join(os.path.dirname(__file__), "../frontend/dist"))
 
 
 
 
 
 
1003
  ASSETS_DIR = os.path.join(FRONTEND_DIST, "assets")
1004
 
1005
  if os.path.isdir(ASSETS_DIR):
 
226
  expose_headers=["*"] # Allow access to response headers
227
  )
228
 
229
+ # Use /tmp for outputs in Hugging Face Spaces (writable directory)
230
+ OUTPUT_DIR = os.environ.get("OUTPUT_DIR", "/tmp/outputs")
231
  os.makedirs(OUTPUT_DIR, exist_ok=True)
232
 
233
  # Create image outputs dir
 
1001
 
1002
  # Serve frontend only if it has been built; avoid startup failure when dist/ is missing.
1003
  FRONTEND_DIST = os.path.abspath(os.path.join(os.path.dirname(__file__), "../frontend/dist"))
1004
+
1005
+ # Check if frontend/dist exists in /app (Docker), otherwise check relative to script location
1006
+ if not os.path.isdir(FRONTEND_DIST):
1007
+ # Fallback for Docker: frontend is copied to ./frontend/dist during build
1008
+ FRONTEND_DIST = os.path.join(os.path.dirname(__file__), "frontend/dist")
1009
+
1010
  ASSETS_DIR = os.path.join(FRONTEND_DIST, "assets")
1011
 
1012
  if os.path.isdir(ASSETS_DIR):