Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
import spaces
|
| 2 |
import gradio as gr
|
| 3 |
import diffusers
|
| 4 |
import torch
|
|
@@ -11,23 +10,21 @@ import open3d as o3d
|
|
| 11 |
import tempfile
|
| 12 |
from skimage import filters
|
| 13 |
import gc
|
| 14 |
-
|
| 15 |
from scipy.ndimage import sobel
|
| 16 |
-
|
| 17 |
import os
|
| 18 |
import torch
|
| 19 |
import diffusers
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
|
| 32 |
|
| 33 |
# Check if CUDA is available
|
|
@@ -41,7 +38,7 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
| 41 |
|
| 42 |
# Reset CUDA environment
|
| 43 |
torch.cuda.empty_cache()
|
| 44 |
-
|
| 45 |
try:
|
| 46 |
print("Loading depth pipeline...")
|
| 47 |
pipe = diffusers.MarigoldDepthPipeline.from_pretrained(
|
|
@@ -61,22 +58,22 @@ try:
|
|
| 61 |
except Exception as e:
|
| 62 |
print(f"Error loading depth pipeline: {type(e).__name__} - {e}")
|
| 63 |
raise
|
| 64 |
-
# Enable XFormers if using GPU
|
| 65 |
-
if device.type == "cuda":
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
else:
|
| 79 |
-
|
| 80 |
|
| 81 |
@spaces.GPU(enable_queue=True)
|
| 82 |
def predict_depth(image: Image.Image):
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import diffusers
|
| 3 |
import torch
|
|
|
|
| 10 |
import tempfile
|
| 11 |
from skimage import filters
|
| 12 |
import gc
|
|
|
|
| 13 |
from scipy.ndimage import sobel
|
|
|
|
| 14 |
import os
|
| 15 |
import torch
|
| 16 |
import diffusers
|
| 17 |
|
| 18 |
+
# Handle GPU availability in Hugging Face Spaces with ZeroGPU
|
| 19 |
+
if os.environ.get("SPACES_ZERO_GPU") is not None:
|
| 20 |
+
import spaces
|
| 21 |
+
else:
|
| 22 |
+
class spaces:
|
| 23 |
+
@staticmethod
|
| 24 |
+
def GPU(func):
|
| 25 |
+
def wrapper(*args, **kwargs):
|
| 26 |
+
return func(*args, **kwargs)
|
| 27 |
+
return wrapper
|
| 28 |
|
| 29 |
|
| 30 |
# Check if CUDA is available
|
|
|
|
| 38 |
|
| 39 |
# Reset CUDA environment
|
| 40 |
torch.cuda.empty_cache()
|
| 41 |
+
|
| 42 |
try:
|
| 43 |
print("Loading depth pipeline...")
|
| 44 |
pipe = diffusers.MarigoldDepthPipeline.from_pretrained(
|
|
|
|
| 58 |
except Exception as e:
|
| 59 |
print(f"Error loading depth pipeline: {type(e).__name__} - {e}")
|
| 60 |
raise
|
| 61 |
+
# # Enable XFormers if using GPU
|
| 62 |
+
# if device.type == "cuda":
|
| 63 |
+
# try:
|
| 64 |
+
# from xformers.ops import memory_efficient_attention
|
| 65 |
+
# print("xformers is installed and operational!")
|
| 66 |
+
# print("Enabling XFormers...")
|
| 67 |
+
# pipe.enable_xformers_memory_efficient_attention()
|
| 68 |
+
# print("XFormers enabled.")
|
| 69 |
+
# except AttributeError:
|
| 70 |
+
# print("XFormers is not supported in the installed version of diffusers or model.")
|
| 71 |
+
# except ImportError:
|
| 72 |
+
# print("XFormers library is not installed. Run `pip install xformers`.")
|
| 73 |
+
# except Exception as e:
|
| 74 |
+
# print(f"Unexpected error enabling XFormers: {type(e).__name__} - {e}")
|
| 75 |
+
# else:
|
| 76 |
+
# print("XFormers not enabled as the device is CPU.")
|
| 77 |
|
| 78 |
@spaces.GPU(enable_queue=True)
|
| 79 |
def predict_depth(image: Image.Image):
|