Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import spaces
|
| 2 |
import time
|
| 3 |
import os
|
|
@@ -14,6 +46,7 @@ from pulid.pipeline_flux import PuLIDPipeline
|
|
| 14 |
from pulid.utils import resize_numpy_image_long
|
| 15 |
|
| 16 |
|
|
|
|
| 17 |
def get_models(name: str, device: torch.device, offload: bool):
|
| 18 |
t5 = load_t5(device, max_length=128)
|
| 19 |
clip = load_clip(device)
|
|
|
|
| 1 |
+
from unittest.mock import MagicMock
|
| 2 |
+
|
| 3 |
+
# Fix 1: Mock device_mesh for torch compatibility
|
| 4 |
+
class MockDeviceMesh:
|
| 5 |
+
def init_device_mesh(self, *args, **kwargs):
|
| 6 |
+
return None
|
| 7 |
+
|
| 8 |
+
if 'torch.distributed.device_mesh' not in sys.modules:
|
| 9 |
+
sys.modules['torch.distributed.device_mesh'] = MockDeviceMesh()
|
| 10 |
+
|
| 11 |
+
# Fix 2: Mock functional_tensor for torchvision compatibility
|
| 12 |
+
try:
|
| 13 |
+
from torchvision.transforms import functional_tensor
|
| 14 |
+
except ImportError:
|
| 15 |
+
mock_functional_tensor = MagicMock()
|
| 16 |
+
|
| 17 |
+
try:
|
| 18 |
+
from torchvision.transforms.functional import rgb_to_grayscale
|
| 19 |
+
mock_functional_tensor.rgb_to_grayscale = rgb_to_grayscale
|
| 20 |
+
except ImportError:
|
| 21 |
+
def rgb_to_grayscale(img, num_output_channels=1):
|
| 22 |
+
import torch
|
| 23 |
+
if len(img.shape) == 4:
|
| 24 |
+
return img.mean(dim=1, keepdim=True)
|
| 25 |
+
elif len(img.shape) == 3:
|
| 26 |
+
return img.mean(dim=0, keepdim=True)
|
| 27 |
+
return img
|
| 28 |
+
mock_functional_tensor.rgb_to_grayscale = rgb_to_grayscale
|
| 29 |
+
|
| 30 |
+
sys.modules['torchvision.transforms.functional_tensor'] = mock_functional_tensor
|
| 31 |
+
|
| 32 |
+
# Now continue with original imports
|
| 33 |
import spaces
|
| 34 |
import time
|
| 35 |
import os
|
|
|
|
| 46 |
from pulid.utils import resize_numpy_image_long
|
| 47 |
|
| 48 |
|
| 49 |
+
|
| 50 |
def get_models(name: str, device: torch.device, offload: bool):
|
| 51 |
t5 = load_t5(device, max_length=128)
|
| 52 |
clip = load_clip(device)
|