Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,34 @@
|
|
1 |
import os
|
2 |
-
|
3 |
-
|
4 |
|
5 |
-
# Fix
|
6 |
-
zerogpu_offload_dir =
|
7 |
if not os.path.exists(zerogpu_offload_dir):
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|