haggai commited on
Commit
2950231
Β·
verified Β·
1 Parent(s): bff1d88

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -5
app.py CHANGED
@@ -1,13 +1,34 @@
1
  import os
2
- # PyTorch 2.8 (temporary hack)
3
- os.system('pip install --upgrade --pre --extra-index-url https://download.pytorch.org/whl/nightly/cu126 "torch<2.9" spaces')
4
 
5
- # Fix ZeroGPU offload directory issue
6
- zerogpu_offload_dir = os.environ.get('ZEROGPU_OFFLOAD_DIR', '/tmp/zerogpu-offload')
7
  if not os.path.exists(zerogpu_offload_dir):
8
- os.makedirs(zerogpu_offload_dir, exist_ok=True)
 
 
 
 
 
 
 
9
  os.environ['ZEROGPU_OFFLOAD_DIR'] = zerogpu_offload_dir
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  # --- 1. Model Download and Setup (Diffusers Backend) ---
13
  import spaces
 
1
  import os
2
+ import sys
3
+ from pathlib import Path
4
 
5
+ # Fix 1: Ensure the offload directory exists with proper permissions
6
+ zerogpu_offload_dir = '/data-nvme/zerogpu-offload'
7
  if not os.path.exists(zerogpu_offload_dir):
8
+ try:
9
+ os.makedirs(zerogpu_offload_dir, exist_ok=True, mode=0o755)
10
+ except Exception as e:
11
+ # Fallback to tmp directory
12
+ zerogpu_offload_dir = '/tmp/zerogpu-offload'
13
+ os.makedirs(zerogpu_offload_dir, exist_ok=True, mode=0o755)
14
+
15
+ # Fix 2: Set environment variable before spaces import
16
  os.environ['ZEROGPU_OFFLOAD_DIR'] = zerogpu_offload_dir
17
 
18
+ # Fix 3: Patch the pathlib.Path.mkdir method to handle FileExistsError
19
+ original_mkdir = Path.mkdir
20
+
21
+ def patched_mkdir(self, mode=0o777, parents=False, exist_ok=False):
22
+ """Patched mkdir that always uses exist_ok=True for ZeroGPU directories"""
23
+ if 'zerogpu-offload' in str(self):
24
+ exist_ok = True
25
+ return original_mkdir(self, mode=mode, parents=parents, exist_ok=exist_ok)
26
+
27
+ # Apply the patch
28
+ Path.mkdir = patched_mkdir
29
+
30
+ print("πŸ”§ Applied ZeroGPU fixes")
31
+
32
 
33
  # --- 1. Model Download and Setup (Diffusers Backend) ---
34
  import spaces