Spaces:
Runtime error
Runtime error
improvements
Browse files
app.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
import cv2
|
| 2 |
import torch
|
| 3 |
import random
|
|
|
|
| 4 |
import numpy as np
|
|
|
|
| 5 |
from PIL import Image
|
| 6 |
from diffusers import (
|
| 7 |
ControlNetModel,
|
|
@@ -43,6 +45,7 @@ pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
|
|
| 43 |
variant="fp16",
|
| 44 |
add_watermarker=False,
|
| 45 |
).to(device)
|
|
|
|
| 46 |
pipe.scheduler = EulerDiscreteScheduler.from_config(
|
| 47 |
pipe.scheduler.config, timestep_spacing="trailing", prediction_type="epsilon"
|
| 48 |
)
|
|
@@ -222,6 +225,8 @@ def create_image(
|
|
| 222 |
controlnet_conditioning_scale=float(control_scale),
|
| 223 |
neg_content_prompt=neg_content_prompt,
|
| 224 |
neg_content_scale=neg_content_scale,
|
|
|
|
|
|
|
| 225 |
)
|
| 226 |
else:
|
| 227 |
images = ip_model.generate(
|
|
@@ -235,8 +240,13 @@ def create_image(
|
|
| 235 |
seed=seed,
|
| 236 |
image=canny_map,
|
| 237 |
controlnet_conditioning_scale=float(control_scale),
|
|
|
|
|
|
|
| 238 |
)
|
| 239 |
-
|
|
|
|
|
|
|
|
|
|
| 240 |
|
| 241 |
|
| 242 |
def pil_to_cv2(image_pil):
|
|
@@ -251,7 +261,7 @@ title = r"""
|
|
| 251 |
"""
|
| 252 |
|
| 253 |
description = r"""
|
| 254 |
-
<b>Forked from <a href='https://github.com/InstantStyle/InstantStyle' target='_blank'
|
| 255 |
<b>Model by <a href='https://huggingface.co/ByteDance/SDXL-Lightning' target='_blank'>SDXL Lightning</a> and <a href='https://huggingface.co/h94/IP-Adapter' target='_blank'>IP-Adapter</a>.</b><br>
|
| 256 |
"""
|
| 257 |
|
|
|
|
| 1 |
import cv2
|
| 2 |
import torch
|
| 3 |
import random
|
| 4 |
+
import tempfile
|
| 5 |
import numpy as np
|
| 6 |
+
from pathlib import Path
|
| 7 |
from PIL import Image
|
| 8 |
from diffusers import (
|
| 9 |
ControlNetModel,
|
|
|
|
| 45 |
variant="fp16",
|
| 46 |
add_watermarker=False,
|
| 47 |
).to(device)
|
| 48 |
+
pipe.set_progress_bar_config(disable=True)
|
| 49 |
pipe.scheduler = EulerDiscreteScheduler.from_config(
|
| 50 |
pipe.scheduler.config, timestep_spacing="trailing", prediction_type="epsilon"
|
| 51 |
)
|
|
|
|
| 225 |
controlnet_conditioning_scale=float(control_scale),
|
| 226 |
neg_content_prompt=neg_content_prompt,
|
| 227 |
neg_content_scale=neg_content_scale,
|
| 228 |
+
width=512,
|
| 229 |
+
height=512,
|
| 230 |
)
|
| 231 |
else:
|
| 232 |
images = ip_model.generate(
|
|
|
|
| 240 |
seed=seed,
|
| 241 |
image=canny_map,
|
| 242 |
controlnet_conditioning_scale=float(control_scale),
|
| 243 |
+
width=512,
|
| 244 |
+
height=512,
|
| 245 |
)
|
| 246 |
+
image = images[0]
|
| 247 |
+
with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as tmpfile:
|
| 248 |
+
image.save(tmpfile, "JPEG", quality=80, optimize=True, progressive=True)
|
| 249 |
+
return Path(tmpfile.name)
|
| 250 |
|
| 251 |
|
| 252 |
def pil_to_cv2(image_pil):
|
|
|
|
| 261 |
"""
|
| 262 |
|
| 263 |
description = r"""
|
| 264 |
+
<b>Forked from <a href='https://github.com/InstantStyle/InstantStyle' target='_blank'>InstantStyle: Free Lunch towards Style-Preserving in Text-to-Image Generation</a>.<br>
|
| 265 |
<b>Model by <a href='https://huggingface.co/ByteDance/SDXL-Lightning' target='_blank'>SDXL Lightning</a> and <a href='https://huggingface.co/h94/IP-Adapter' target='_blank'>IP-Adapter</a>.</b><br>
|
| 266 |
"""
|
| 267 |
|