Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,34 @@
|
|
| 1 |
-
import
|
| 2 |
import torch
|
| 3 |
-
from
|
|
|
|
| 4 |
|
| 5 |
-
path_to_config = 'ControlNet-XS-main/configs/inference/sdxl/sdxl_encD_canny_48m.yaml'
|
| 6 |
-
model = cu.create_model(path_to_config).to('cuda')
|
| 7 |
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
size = 768
|
| 13 |
-
num_samples=2
|
| 14 |
-
|
| 15 |
-
image = cu.get_image(image_path, size=size)
|
| 16 |
-
edges = cu.get_canny_edges(image, low_th=canny_low_th, high_th=canny_high_th)
|
| 17 |
-
|
| 18 |
-
samples, controls = cu.get_sdxl_sample(
|
| 19 |
-
guidance=edges,
|
| 20 |
-
ddim_steps=10,
|
| 21 |
-
num_samples=num_samples,
|
| 22 |
-
model=model,
|
| 23 |
-
shape=[4, size // 8, size // 8],
|
| 24 |
-
control_scale=0.95,
|
| 25 |
-
prompt='cinematic, shoe in the streets, made from meat, photorealistic shoe, highly detailed',
|
| 26 |
-
n_prompt='lowres, bad anatomy, worst quality, low quality',
|
| 27 |
)
|
|
|
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffusers import AutoencoderKL, StableDiffusionXLControlNetPipeline, ControlNetModel, UniPCMultistepScheduler
|
| 2 |
import torch
|
| 3 |
+
from controlnet_aux import OpenposeDetector
|
| 4 |
+
from diffusers.utils import load_image
|
| 5 |
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# Compute openpose conditioning image.
|
| 8 |
+
openpose = OpenposeDetector.from_pretrained("lllyasviel/ControlNet")
|
| 9 |
|
| 10 |
+
image = load_image(
|
| 11 |
+
"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/person.png"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
)
|
| 13 |
+
openpose_image = openpose(image)
|
| 14 |
|
| 15 |
+
# Initialize ControlNet pipeline.
|
| 16 |
+
controlnet = ControlNetModel.from_pretrained("thibaud/controlnet-openpose-sdxl-1.0")
|
| 17 |
+
pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
|
| 18 |
+
"stabilityai/stable-diffusion-xl-base-1.0", controlnet=controlnet
|
| 19 |
+
)
|
| 20 |
+
#pipe.enable_model_cpu_offload()
|
| 21 |
|
| 22 |
+
def pose_calc():
|
| 23 |
+
# Infer.
|
| 24 |
+
prompt = "Darth vader dancing in a desert, high quality"
|
| 25 |
+
negative_prompt = "low quality, bad quality"
|
| 26 |
+
images = pipe(
|
| 27 |
+
prompt,
|
| 28 |
+
negative_prompt=negative_prompt,
|
| 29 |
+
num_inference_steps=25,
|
| 30 |
+
num_images_per_prompt=4,
|
| 31 |
+
image=openpose_image.resize((1024, 1024)),
|
| 32 |
+
generator=torch.manual_seed(97),
|
| 33 |
+
).images
|
| 34 |
+
return images[0]
|