Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,9 @@
|
|
|
|
|
|
1 |
import sys
|
2 |
import types
|
3 |
|
|
|
4 |
torch_six = types.ModuleType('torch._six')
|
5 |
torch_six.string_classes = (str,) # In Python 3, string_classes is just (str,)
|
6 |
|
@@ -12,6 +15,24 @@ if 'torch' not in sys.modules:
|
|
12 |
sys.modules['torch._six'] = torch_six
|
13 |
torch._six = torch_six
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
from pydoc import describe
|
16 |
import gradio as gr
|
17 |
import torch
|
@@ -25,9 +46,9 @@ from ldm.util import instantiate_from_config
|
|
25 |
from huggingface_hub import hf_hub_download
|
26 |
import spaces
|
27 |
|
|
|
28 |
model_path_e = hf_hub_download(repo_id="multimodalart/compvis-latent-diffusion-text2img-large", filename="txt2img-f8-large.ckpt")
|
29 |
|
30 |
-
#@title Import stuff
|
31 |
import argparse, os, sys, glob
|
32 |
import numpy as np
|
33 |
from PIL import Image
|
|
|
1 |
+
# Add this code at the very beginning of your script, before any other imports
|
2 |
+
|
3 |
import sys
|
4 |
import types
|
5 |
|
6 |
+
# Create a fake torch._six module with string_classes
|
7 |
torch_six = types.ModuleType('torch._six')
|
8 |
torch_six.string_classes = (str,) # In Python 3, string_classes is just (str,)
|
9 |
|
|
|
15 |
sys.modules['torch._six'] = torch_six
|
16 |
torch._six = torch_six
|
17 |
|
18 |
+
# Monkey patch for pytorch_lightning.utilities.distributed
|
19 |
+
try:
|
20 |
+
from pytorch_lightning.utilities.rank_zero import rank_zero_only
|
21 |
+
# Create the old module path
|
22 |
+
pl_utils_dist = types.ModuleType('pytorch_lightning.utilities.distributed')
|
23 |
+
pl_utils_dist.rank_zero_only = rank_zero_only
|
24 |
+
sys.modules['pytorch_lightning.utilities.distributed'] = pl_utils_dist
|
25 |
+
except ImportError:
|
26 |
+
# If even the new import fails, create a dummy decorator
|
27 |
+
def rank_zero_only(fn):
|
28 |
+
"""Dummy decorator that just returns the function as-is"""
|
29 |
+
return fn
|
30 |
+
|
31 |
+
pl_utils_dist = types.ModuleType('pytorch_lightning.utilities.distributed')
|
32 |
+
pl_utils_dist.rank_zero_only = rank_zero_only
|
33 |
+
sys.modules['pytorch_lightning.utilities.distributed'] = pl_utils_dist
|
34 |
+
|
35 |
+
# Now continue with your original imports
|
36 |
from pydoc import describe
|
37 |
import gradio as gr
|
38 |
import torch
|
|
|
46 |
from huggingface_hub import hf_hub_download
|
47 |
import spaces
|
48 |
|
49 |
+
# Rest of your code continues here...
|
50 |
model_path_e = hf_hub_download(repo_id="multimodalart/compvis-latent-diffusion-text2img-large", filename="txt2img-f8-large.ckpt")
|
51 |
|
|
|
52 |
import argparse, os, sys, glob
|
53 |
import numpy as np
|
54 |
from PIL import Image
|