Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,24 +2,33 @@ import torch
|
|
| 2 |
from diffusers.utils import load_image
|
| 3 |
from diffusers import FluxControlNetPipeline, FluxControlNetModel
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
base_model = 'black-forest-labs/FLUX.1-dev'
|
| 6 |
controlnet_model = 'InstantX/FLUX.1-dev-Controlnet-Union'
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
|
|
|
| 10 |
pipe.to("cuda")
|
| 11 |
|
| 12 |
control_image_canny = load_image("https://huggingface.co/InstantX/FLUX.1-dev-Controlnet-Union-alpha/resolve/main/images/canny.jpg")
|
| 13 |
controlnet_conditioning_scale = 0.5
|
| 14 |
control_mode = 0
|
| 15 |
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
prompt = 'A bohemian-style female travel blogger with sun-kissed skin and messy beach waves.'
|
| 19 |
|
| 20 |
image = pipe(
|
| 21 |
prompt,
|
| 22 |
-
control_image=
|
| 23 |
control_mode=control_mode,
|
| 24 |
width=width,
|
| 25 |
height=height,
|
|
@@ -28,3 +37,6 @@ image = pipe(
|
|
| 28 |
guidance_scale=3.5,
|
| 29 |
).images[0]
|
| 30 |
image.save("image.jpg")
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
from diffusers.utils import load_image
|
| 3 |
from diffusers import FluxControlNetPipeline, FluxControlNetModel
|
| 4 |
|
| 5 |
+
# Clear unnecessary memory
|
| 6 |
+
torch.cuda.empty_cache()
|
| 7 |
+
|
| 8 |
+
# Set the environment variable to handle memory fragmentation
|
| 9 |
+
import os
|
| 10 |
+
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
|
| 11 |
+
|
| 12 |
base_model = 'black-forest-labs/FLUX.1-dev'
|
| 13 |
controlnet_model = 'InstantX/FLUX.1-dev-Controlnet-Union'
|
| 14 |
|
| 15 |
+
# Use a smaller precision if possible
|
| 16 |
+
controlnet = FluxControlNetModel.from_pretrained(controlnet_model, torch_dtype=torch.float16)
|
| 17 |
+
pipe = FluxControlNetPipeline.from_pretrained(base_model, controlnet=controlnet, torch_dtype=torch.float16)
|
| 18 |
pipe.to("cuda")
|
| 19 |
|
| 20 |
control_image_canny = load_image("https://huggingface.co/InstantX/FLUX.1-dev-Controlnet-Union-alpha/resolve/main/images/canny.jpg")
|
| 21 |
controlnet_conditioning_scale = 0.5
|
| 22 |
control_mode = 0
|
| 23 |
|
| 24 |
+
# Ensure that image is loaded correctly
|
| 25 |
+
width, height = control_image_canny.size
|
| 26 |
|
| 27 |
prompt = 'A bohemian-style female travel blogger with sun-kissed skin and messy beach waves.'
|
| 28 |
|
| 29 |
image = pipe(
|
| 30 |
prompt,
|
| 31 |
+
control_image=control_image_canny,
|
| 32 |
control_mode=control_mode,
|
| 33 |
width=width,
|
| 34 |
height=height,
|
|
|
|
| 37 |
guidance_scale=3.5,
|
| 38 |
).images[0]
|
| 39 |
image.save("image.jpg")
|
| 40 |
+
|
| 41 |
+
# Empty cache after the operation to free up memory
|
| 42 |
+
torch.cuda.empty_cache()
|