Spaces:
Running
on
Zero
Running
on
Zero
check spaces zero
Browse files
app.py
CHANGED
|
@@ -16,6 +16,7 @@ import time
|
|
| 16 |
import cv2
|
| 17 |
import numpy as np
|
| 18 |
|
|
|
|
| 19 |
|
| 20 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 21 |
dtype = torch.float16
|
|
@@ -42,10 +43,13 @@ pipe = StableDiffusionXLControlNetImg2ImgPipeline.from_pretrained(
|
|
| 42 |
use_safetensors=True,
|
| 43 |
scheduler=scheduler,
|
| 44 |
)
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
| 47 |
pipe.enable_vae_tiling()
|
| 48 |
|
|
|
|
| 49 |
compel = Compel(
|
| 50 |
tokenizer=[pipe.tokenizer, pipe.tokenizer_2],
|
| 51 |
text_encoder=[pipe.text_encoder, pipe.text_encoder_2],
|
|
@@ -54,6 +58,9 @@ compel = Compel(
|
|
| 54 |
)
|
| 55 |
pipe = pipe.to(device)
|
| 56 |
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
def pad_image(image):
|
| 59 |
w, h = image.size
|
|
@@ -87,7 +94,8 @@ def predict(
|
|
| 87 |
controlnet_end=1.0,
|
| 88 |
progress=gr.Progress(track_tqdm=True),
|
| 89 |
):
|
| 90 |
-
|
|
|
|
| 91 |
if input_image is None:
|
| 92 |
raise gr.Error("Please upload an image.")
|
| 93 |
padded_image = pad_image(input_image).resize((1024, 1024)).convert("RGB")
|
|
|
|
| 16 |
import cv2
|
| 17 |
import numpy as np
|
| 18 |
|
| 19 |
+
IS_SPACES_ZERO = os.environ.get("SPACES_ZERO_GPU", "0") == "1"
|
| 20 |
|
| 21 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 22 |
dtype = torch.float16
|
|
|
|
| 43 |
use_safetensors=True,
|
| 44 |
scheduler=scheduler,
|
| 45 |
)
|
| 46 |
+
if not IS_SPACES_ZERO:
|
| 47 |
+
pipe.enable_xformers_memory_efficient_attention()
|
| 48 |
+
pipe.enable_model_cpu_offload()
|
| 49 |
+
|
| 50 |
pipe.enable_vae_tiling()
|
| 51 |
|
| 52 |
+
|
| 53 |
compel = Compel(
|
| 54 |
tokenizer=[pipe.tokenizer, pipe.tokenizer_2],
|
| 55 |
text_encoder=[pipe.text_encoder, pipe.text_encoder_2],
|
|
|
|
| 58 |
)
|
| 59 |
pipe = pipe.to(device)
|
| 60 |
|
| 61 |
+
if not IS_SPACES_ZERO:
|
| 62 |
+
apply_hidiffusion(pipe)
|
| 63 |
+
|
| 64 |
|
| 65 |
def pad_image(image):
|
| 66 |
w, h = image.size
|
|
|
|
| 94 |
controlnet_end=1.0,
|
| 95 |
progress=gr.Progress(track_tqdm=True),
|
| 96 |
):
|
| 97 |
+
if IS_SPACES_ZERO:
|
| 98 |
+
apply_hidiffusion(pipe)
|
| 99 |
if input_image is None:
|
| 100 |
raise gr.Error("Please upload an image.")
|
| 101 |
padded_image = pad_image(input_image).resize((1024, 1024)).convert("RGB")
|