Spaces:
Running
on
Zero
Running
on
Zero
Upload app.py
Browse filesSorry. The earlier email was a false alarm. It was just stored in the cache.
So I fixed it in a messy way. It is now inferred.
app.py
CHANGED
|
@@ -1,369 +1,373 @@
|
|
| 1 |
-
import spaces
|
| 2 |
-
import gradio as gr
|
| 3 |
-
from gradio_imageslider import ImageSlider
|
| 4 |
-
import torch
|
| 5 |
-
|
| 6 |
-
torch.jit.script = lambda f: f
|
| 7 |
-
from hidiffusion import apply_hidiffusion
|
| 8 |
-
from diffusers import (
|
| 9 |
-
ControlNetModel,
|
| 10 |
-
StableDiffusionXLControlNetImg2ImgPipeline,
|
| 11 |
-
DDIMScheduler,
|
| 12 |
-
)
|
| 13 |
-
from controlnet_aux import AnylineDetector
|
| 14 |
-
from compel import Compel, ReturnedEmbeddingsType
|
| 15 |
-
from PIL import Image
|
| 16 |
-
import os
|
| 17 |
-
import time
|
| 18 |
-
import numpy as np
|
| 19 |
-
|
| 20 |
-
IS_SPACES_ZERO = os.environ.get("SPACES_ZERO_GPU", "0") == "1"
|
| 21 |
-
IS_SPACE = os.environ.get("SPACE_ID", None) is not None
|
| 22 |
-
|
| 23 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 24 |
-
dtype = torch.float16
|
| 25 |
-
|
| 26 |
-
LOW_MEMORY = os.getenv("LOW_MEMORY", "0") == "1"
|
| 27 |
-
|
| 28 |
-
print(f"device: {device}")
|
| 29 |
-
print(f"dtype: {dtype}")
|
| 30 |
-
print(f"low memory: {LOW_MEMORY}")
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
model = "stabilityai/stable-diffusion-xl-base-1.0"
|
| 34 |
-
# model = "stabilityai/sdxl-turbo"
|
| 35 |
-
# vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=dtype)
|
| 36 |
-
scheduler = DDIMScheduler.from_pretrained(model, subfolder="scheduler")
|
| 37 |
-
# controlnet = ControlNetModel.from_pretrained(
|
| 38 |
-
# "diffusers/controlnet-canny-sdxl-1.0", torch_dtype=torch.float16
|
| 39 |
-
# )
|
| 40 |
-
controlnet = ControlNetModel.from_pretrained(
|
| 41 |
-
"TheMistoAI/MistoLine",
|
| 42 |
-
torch_dtype=torch.float16,
|
| 43 |
-
revision="refs/pr/3",
|
| 44 |
-
variant="fp16",
|
| 45 |
-
)
|
| 46 |
-
pipe = StableDiffusionXLControlNetImg2ImgPipeline.from_pretrained(
|
| 47 |
-
model,
|
| 48 |
-
controlnet=controlnet,
|
| 49 |
-
torch_dtype=dtype,
|
| 50 |
-
variant="fp16",
|
| 51 |
-
use_safetensors=True,
|
| 52 |
-
scheduler=scheduler,
|
| 53 |
-
)
|
| 54 |
-
|
| 55 |
-
compel = Compel(
|
| 56 |
-
tokenizer=[pipe.tokenizer, pipe.tokenizer_2],
|
| 57 |
-
text_encoder=[pipe.text_encoder, pipe.text_encoder_2],
|
| 58 |
-
returned_embeddings_type=ReturnedEmbeddingsType.PENULTIMATE_HIDDEN_STATES_NON_NORMALIZED,
|
| 59 |
-
requires_pooled=[False, True],
|
| 60 |
-
)
|
| 61 |
-
pipe = pipe.to(device)
|
| 62 |
-
|
| 63 |
-
if not IS_SPACES_ZERO:
|
| 64 |
-
apply_hidiffusion(pipe)
|
| 65 |
-
# pipe.enable_xformers_memory_efficient_attention()
|
| 66 |
-
pipe.enable_model_cpu_offload()
|
| 67 |
-
pipe.enable_vae_tiling()
|
| 68 |
-
|
| 69 |
-
anyline = AnylineDetector.from_pretrained(
|
| 70 |
-
"TheMistoAI/MistoLine", filename="MTEED.pth", subfolder="Anyline"
|
| 71 |
-
).to(device)
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
def pad_image(image):
|
| 75 |
-
w, h = image.size
|
| 76 |
-
if w == h:
|
| 77 |
-
return image
|
| 78 |
-
elif w > h:
|
| 79 |
-
new_image = Image.new(image.mode, (w, w), (0, 0, 0))
|
| 80 |
-
pad_w = 0
|
| 81 |
-
pad_h = (w - h) // 2
|
| 82 |
-
new_image.paste(image, (0, pad_h))
|
| 83 |
-
return new_image
|
| 84 |
-
else:
|
| 85 |
-
new_image = Image.new(image.mode, (h, h), (0, 0, 0))
|
| 86 |
-
pad_w = (h - w) // 2
|
| 87 |
-
pad_h = 0
|
| 88 |
-
new_image.paste(image, (pad_w, 0))
|
| 89 |
-
return new_image
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
@spaces.GPU(duration=120)
|
| 93 |
-
def predict(
|
| 94 |
-
input_image,
|
| 95 |
-
prompt,
|
| 96 |
-
negative_prompt,
|
| 97 |
-
seed,
|
| 98 |
-
guidance_scale=8.5,
|
| 99 |
-
scale=2,
|
| 100 |
-
controlnet_conditioning_scale=0.5,
|
| 101 |
-
strength=1.0,
|
| 102 |
-
controlnet_start=0.0,
|
| 103 |
-
controlnet_end=1.0,
|
| 104 |
-
guassian_sigma=2.0,
|
| 105 |
-
intensity_threshold=3,
|
| 106 |
-
progress=gr.Progress(track_tqdm=True),
|
| 107 |
-
):
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
)
|
| 178 |
-
|
| 179 |
-
label="
|
| 180 |
-
|
| 181 |
-
)
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
inputs=inputs,
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import spaces
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from gradio_imageslider import ImageSlider
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
torch.jit.script = lambda f: f
|
| 7 |
+
from hidiffusion import apply_hidiffusion
|
| 8 |
+
from diffusers import (
|
| 9 |
+
ControlNetModel,
|
| 10 |
+
StableDiffusionXLControlNetImg2ImgPipeline,
|
| 11 |
+
DDIMScheduler,
|
| 12 |
+
)
|
| 13 |
+
from controlnet_aux import AnylineDetector
|
| 14 |
+
from compel import Compel, ReturnedEmbeddingsType
|
| 15 |
+
from PIL import Image
|
| 16 |
+
import os
|
| 17 |
+
import time
|
| 18 |
+
import numpy as np
|
| 19 |
+
|
| 20 |
+
IS_SPACES_ZERO = os.environ.get("SPACES_ZERO_GPU", "0") == "1"
|
| 21 |
+
IS_SPACE = os.environ.get("SPACE_ID", None) is not None
|
| 22 |
+
|
| 23 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 24 |
+
dtype = torch.float16
|
| 25 |
+
|
| 26 |
+
LOW_MEMORY = os.getenv("LOW_MEMORY", "0") == "1"
|
| 27 |
+
|
| 28 |
+
print(f"device: {device}")
|
| 29 |
+
print(f"dtype: {dtype}")
|
| 30 |
+
print(f"low memory: {LOW_MEMORY}")
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
model = "stabilityai/stable-diffusion-xl-base-1.0"
|
| 34 |
+
# model = "stabilityai/sdxl-turbo"
|
| 35 |
+
# vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=dtype)
|
| 36 |
+
scheduler = DDIMScheduler.from_pretrained(model, subfolder="scheduler")
|
| 37 |
+
# controlnet = ControlNetModel.from_pretrained(
|
| 38 |
+
# "diffusers/controlnet-canny-sdxl-1.0", torch_dtype=torch.float16
|
| 39 |
+
# )
|
| 40 |
+
controlnet = ControlNetModel.from_pretrained(
|
| 41 |
+
"TheMistoAI/MistoLine",
|
| 42 |
+
torch_dtype=torch.float16,
|
| 43 |
+
revision="refs/pr/3",
|
| 44 |
+
variant="fp16",
|
| 45 |
+
)
|
| 46 |
+
pipe = StableDiffusionXLControlNetImg2ImgPipeline.from_pretrained(
|
| 47 |
+
model,
|
| 48 |
+
controlnet=controlnet,
|
| 49 |
+
torch_dtype=dtype,
|
| 50 |
+
variant="fp16",
|
| 51 |
+
use_safetensors=True,
|
| 52 |
+
scheduler=scheduler,
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
compel = Compel(
|
| 56 |
+
tokenizer=[pipe.tokenizer, pipe.tokenizer_2],
|
| 57 |
+
text_encoder=[pipe.text_encoder, pipe.text_encoder_2],
|
| 58 |
+
returned_embeddings_type=ReturnedEmbeddingsType.PENULTIMATE_HIDDEN_STATES_NON_NORMALIZED,
|
| 59 |
+
requires_pooled=[False, True],
|
| 60 |
+
)
|
| 61 |
+
#pipe = pipe.to(device)
|
| 62 |
+
|
| 63 |
+
if not IS_SPACES_ZERO:
|
| 64 |
+
apply_hidiffusion(pipe)
|
| 65 |
+
# pipe.enable_xformers_memory_efficient_attention()
|
| 66 |
+
pipe.enable_model_cpu_offload()
|
| 67 |
+
pipe.enable_vae_tiling()
|
| 68 |
+
|
| 69 |
+
anyline = AnylineDetector.from_pretrained(
|
| 70 |
+
"TheMistoAI/MistoLine", filename="MTEED.pth", subfolder="Anyline"
|
| 71 |
+
).to("cpu") #.to(device)
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def pad_image(image):
|
| 75 |
+
w, h = image.size
|
| 76 |
+
if w == h:
|
| 77 |
+
return image
|
| 78 |
+
elif w > h:
|
| 79 |
+
new_image = Image.new(image.mode, (w, w), (0, 0, 0))
|
| 80 |
+
pad_w = 0
|
| 81 |
+
pad_h = (w - h) // 2
|
| 82 |
+
new_image.paste(image, (0, pad_h))
|
| 83 |
+
return new_image
|
| 84 |
+
else:
|
| 85 |
+
new_image = Image.new(image.mode, (h, h), (0, 0, 0))
|
| 86 |
+
pad_w = (h - w) // 2
|
| 87 |
+
pad_h = 0
|
| 88 |
+
new_image.paste(image, (pad_w, 0))
|
| 89 |
+
return new_image
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
@spaces.GPU(duration=120)
|
| 93 |
+
def predict(
|
| 94 |
+
input_image,
|
| 95 |
+
prompt,
|
| 96 |
+
negative_prompt,
|
| 97 |
+
seed,
|
| 98 |
+
guidance_scale=8.5,
|
| 99 |
+
scale=2,
|
| 100 |
+
controlnet_conditioning_scale=0.5,
|
| 101 |
+
strength=1.0,
|
| 102 |
+
controlnet_start=0.0,
|
| 103 |
+
controlnet_end=1.0,
|
| 104 |
+
guassian_sigma=2.0,
|
| 105 |
+
intensity_threshold=3,
|
| 106 |
+
progress=gr.Progress(track_tqdm=True),
|
| 107 |
+
):
|
| 108 |
+
global pipe
|
| 109 |
+
global anyline
|
| 110 |
+
pipe = pipe.to(device)
|
| 111 |
+
anyline.to(device)
|
| 112 |
+
if IS_SPACES_ZERO:
|
| 113 |
+
apply_hidiffusion(pipe)
|
| 114 |
+
if input_image is None:
|
| 115 |
+
raise gr.Error("Please upload an image.")
|
| 116 |
+
padded_image = pad_image(input_image).resize((1024, 1024)).convert("RGB")
|
| 117 |
+
conditioning, pooled = compel([prompt, negative_prompt])
|
| 118 |
+
generator = torch.manual_seed(seed)
|
| 119 |
+
last_time = time.time()
|
| 120 |
+
anyline_image = anyline(
|
| 121 |
+
padded_image,
|
| 122 |
+
detect_resolution=1280,
|
| 123 |
+
guassian_sigma=max(0.01, guassian_sigma),
|
| 124 |
+
intensity_threshold=intensity_threshold,
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
images = pipe(
|
| 128 |
+
image=padded_image,
|
| 129 |
+
control_image=anyline_image,
|
| 130 |
+
strength=strength,
|
| 131 |
+
prompt_embeds=conditioning[0:1],
|
| 132 |
+
pooled_prompt_embeds=pooled[0:1],
|
| 133 |
+
negative_prompt_embeds=conditioning[1:2],
|
| 134 |
+
negative_pooled_prompt_embeds=pooled[1:2],
|
| 135 |
+
width=1024 * scale,
|
| 136 |
+
height=1024 * scale,
|
| 137 |
+
controlnet_conditioning_scale=float(controlnet_conditioning_scale),
|
| 138 |
+
controlnet_start=float(controlnet_start),
|
| 139 |
+
controlnet_end=float(controlnet_end),
|
| 140 |
+
generator=generator,
|
| 141 |
+
num_inference_steps=30,
|
| 142 |
+
guidance_scale=guidance_scale,
|
| 143 |
+
eta=1.0,
|
| 144 |
+
)
|
| 145 |
+
print(f"Time taken: {time.time() - last_time}")
|
| 146 |
+
return (padded_image, images.images[0]), padded_image, anyline_image
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
css = """
|
| 150 |
+
#intro{
|
| 151 |
+
# max-width: 32rem;
|
| 152 |
+
# text-align: center;
|
| 153 |
+
# margin: 0 auto;
|
| 154 |
+
}
|
| 155 |
+
"""
|
| 156 |
+
|
| 157 |
+
with gr.Blocks(css=css) as demo:
|
| 158 |
+
gr.Markdown(
|
| 159 |
+
"""
|
| 160 |
+
# Enhance This
|
| 161 |
+
### HiDiffusion SDXL
|
| 162 |
+
|
| 163 |
+
[HiDiffusion](https://github.com/megvii-research/HiDiffusion) enables higher-resolution image generation.
|
| 164 |
+
You can upload an initial image and prompt to generate an enhanced version.
|
| 165 |
+
SDXL Controlnet [TheMistoAI/MistoLine](https://huggingface.co/TheMistoAI/MistoLine)
|
| 166 |
+
[Duplicate Space](https://huggingface.co/spaces/radames/Enhance-This-HiDiffusion-SDXL?duplicate=true) to avoid the queue.
|
| 167 |
+
|
| 168 |
+
<small>
|
| 169 |
+
<b>Notes</b> The author advises against the term "super resolution" because it's more like image-to-image generation than enhancement, but it's still a lot of fun!
|
| 170 |
+
|
| 171 |
+
</small>
|
| 172 |
+
""",
|
| 173 |
+
elem_id="intro",
|
| 174 |
+
)
|
| 175 |
+
with gr.Row():
|
| 176 |
+
with gr.Column(scale=1):
|
| 177 |
+
image_input = gr.Image(type="pil", label="Input Image")
|
| 178 |
+
prompt = gr.Textbox(
|
| 179 |
+
label="Prompt",
|
| 180 |
+
info="The prompt is very important to get the desired results. Please try to describe the image as best as you can. Accepts Compel Syntax",
|
| 181 |
+
)
|
| 182 |
+
negative_prompt = gr.Textbox(
|
| 183 |
+
label="Negative Prompt",
|
| 184 |
+
value="blurry, ugly, duplicate, poorly drawn, deformed, mosaic",
|
| 185 |
+
)
|
| 186 |
+
seed = gr.Slider(
|
| 187 |
+
minimum=0,
|
| 188 |
+
maximum=2**64 - 1,
|
| 189 |
+
value=1415926535897932,
|
| 190 |
+
step=1,
|
| 191 |
+
label="Seed",
|
| 192 |
+
randomize=True,
|
| 193 |
+
)
|
| 194 |
+
with gr.Accordion(label="Advanced", open=False):
|
| 195 |
+
guidance_scale = gr.Slider(
|
| 196 |
+
minimum=0,
|
| 197 |
+
maximum=50,
|
| 198 |
+
value=8.5,
|
| 199 |
+
step=0.001,
|
| 200 |
+
label="Guidance Scale",
|
| 201 |
+
)
|
| 202 |
+
scale = gr.Slider(
|
| 203 |
+
minimum=1,
|
| 204 |
+
maximum=5,
|
| 205 |
+
value=2,
|
| 206 |
+
step=1,
|
| 207 |
+
label="Magnification Scale",
|
| 208 |
+
interactive=not IS_SPACE,
|
| 209 |
+
)
|
| 210 |
+
controlnet_conditioning_scale = gr.Slider(
|
| 211 |
+
minimum=0,
|
| 212 |
+
maximum=1,
|
| 213 |
+
step=0.001,
|
| 214 |
+
value=0.5,
|
| 215 |
+
label="ControlNet Conditioning Scale",
|
| 216 |
+
)
|
| 217 |
+
strength = gr.Slider(
|
| 218 |
+
minimum=0,
|
| 219 |
+
maximum=1,
|
| 220 |
+
step=0.001,
|
| 221 |
+
value=1,
|
| 222 |
+
label="Strength",
|
| 223 |
+
)
|
| 224 |
+
controlnet_start = gr.Slider(
|
| 225 |
+
minimum=0,
|
| 226 |
+
maximum=1,
|
| 227 |
+
step=0.001,
|
| 228 |
+
value=0.0,
|
| 229 |
+
label="ControlNet Start",
|
| 230 |
+
)
|
| 231 |
+
controlnet_end = gr.Slider(
|
| 232 |
+
minimum=0.0,
|
| 233 |
+
maximum=1.0,
|
| 234 |
+
step=0.001,
|
| 235 |
+
value=1.0,
|
| 236 |
+
label="ControlNet End",
|
| 237 |
+
)
|
| 238 |
+
guassian_sigma = gr.Slider(
|
| 239 |
+
minimum=0.01,
|
| 240 |
+
maximum=10.0,
|
| 241 |
+
step=0.1,
|
| 242 |
+
value=2.0,
|
| 243 |
+
label="(Anyline) Guassian Sigma",
|
| 244 |
+
)
|
| 245 |
+
intensity_threshold = gr.Slider(
|
| 246 |
+
minimum=0,
|
| 247 |
+
maximum=255,
|
| 248 |
+
step=1,
|
| 249 |
+
value=3,
|
| 250 |
+
label="(Anyline) Intensity Threshold",
|
| 251 |
+
)
|
| 252 |
+
|
| 253 |
+
btn = gr.Button()
|
| 254 |
+
with gr.Column(scale=2):
|
| 255 |
+
with gr.Group():
|
| 256 |
+
image_slider = ImageSlider(position=0.5)
|
| 257 |
+
with gr.Row():
|
| 258 |
+
padded_image = gr.Image(type="pil", label="Padded Image")
|
| 259 |
+
anyline_image = gr.Image(type="pil", label="Anyline Image")
|
| 260 |
+
inputs = [
|
| 261 |
+
image_input,
|
| 262 |
+
prompt,
|
| 263 |
+
negative_prompt,
|
| 264 |
+
seed,
|
| 265 |
+
guidance_scale,
|
| 266 |
+
scale,
|
| 267 |
+
controlnet_conditioning_scale,
|
| 268 |
+
strength,
|
| 269 |
+
controlnet_start,
|
| 270 |
+
controlnet_end,
|
| 271 |
+
guassian_sigma,
|
| 272 |
+
intensity_threshold,
|
| 273 |
+
]
|
| 274 |
+
outputs = [image_slider, padded_image, anyline_image]
|
| 275 |
+
btn.click(lambda x: None, inputs=None, outputs=image_slider).then(
|
| 276 |
+
fn=predict, inputs=inputs, outputs=outputs
|
| 277 |
+
)
|
| 278 |
+
gr.Examples(
|
| 279 |
+
fn=predict,
|
| 280 |
+
inputs=inputs,
|
| 281 |
+
outputs=outputs,
|
| 282 |
+
examples=[
|
| 283 |
+
[
|
| 284 |
+
"./examples/lara.jpeg",
|
| 285 |
+
"photography of lara croft 8k high definition award winning",
|
| 286 |
+
"blurry, ugly, duplicate, poorly drawn, deformed, mosaic",
|
| 287 |
+
5436236241,
|
| 288 |
+
8.5,
|
| 289 |
+
2,
|
| 290 |
+
0.8,
|
| 291 |
+
1.0,
|
| 292 |
+
0.0,
|
| 293 |
+
0.9,
|
| 294 |
+
2,
|
| 295 |
+
3,
|
| 296 |
+
],
|
| 297 |
+
[
|
| 298 |
+
"./examples/cybetruck.jpeg",
|
| 299 |
+
"photo of tesla cybertruck futuristic car 8k high definition on a sand dune in mars, future",
|
| 300 |
+
"blurry, ugly, duplicate, poorly drawn, deformed, mosaic",
|
| 301 |
+
383472451451,
|
| 302 |
+
8.5,
|
| 303 |
+
2,
|
| 304 |
+
0.8,
|
| 305 |
+
0.8,
|
| 306 |
+
0.0,
|
| 307 |
+
0.9,
|
| 308 |
+
2,
|
| 309 |
+
3,
|
| 310 |
+
],
|
| 311 |
+
[
|
| 312 |
+
"./examples/jesus.png",
|
| 313 |
+
"a photorealistic painting of Jesus Christ, 4k high definition",
|
| 314 |
+
"blurry, ugly, duplicate, poorly drawn, deformed, mosaic",
|
| 315 |
+
13317204146129588000,
|
| 316 |
+
8.5,
|
| 317 |
+
2,
|
| 318 |
+
0.8,
|
| 319 |
+
0.8,
|
| 320 |
+
0.0,
|
| 321 |
+
0.9,
|
| 322 |
+
2,
|
| 323 |
+
3,
|
| 324 |
+
],
|
| 325 |
+
[
|
| 326 |
+
"./examples/anna-sullivan-DioLM8ViiO8-unsplash.jpg",
|
| 327 |
+
"A crowded stadium with enthusiastic fans watching a daytime sporting event, the stands filled with colorful attire and the sun casting a warm glow",
|
| 328 |
+
"blurry, ugly, duplicate, poorly drawn, deformed, mosaic",
|
| 329 |
+
5623124123512,
|
| 330 |
+
8.5,
|
| 331 |
+
2,
|
| 332 |
+
0.8,
|
| 333 |
+
0.8,
|
| 334 |
+
0.0,
|
| 335 |
+
0.9,
|
| 336 |
+
2,
|
| 337 |
+
3,
|
| 338 |
+
],
|
| 339 |
+
[
|
| 340 |
+
"./examples/img_aef651cb-2919-499d-aa49-6d4e2e21a56e_1024.jpg",
|
| 341 |
+
"a large red flower on a black background 4k high definition",
|
| 342 |
+
"blurry, ugly, duplicate, poorly drawn, deformed, mosaic",
|
| 343 |
+
23123412341234,
|
| 344 |
+
8.5,
|
| 345 |
+
2,
|
| 346 |
+
0.8,
|
| 347 |
+
0.8,
|
| 348 |
+
0.0,
|
| 349 |
+
0.9,
|
| 350 |
+
2,
|
| 351 |
+
3,
|
| 352 |
+
],
|
| 353 |
+
[
|
| 354 |
+
"./examples/huggingface.jpg",
|
| 355 |
+
"photo realistic huggingface human emoji costume, round, yellow, (human skin)+++ (human texture)+++",
|
| 356 |
+
"blurry, ugly, duplicate, poorly drawn, deformed, mosaic, emoji cartoon, drawing, pixelated",
|
| 357 |
+
12312353423,
|
| 358 |
+
15.206,
|
| 359 |
+
2,
|
| 360 |
+
0.364,
|
| 361 |
+
0.8,
|
| 362 |
+
0.0,
|
| 363 |
+
0.9,
|
| 364 |
+
2,
|
| 365 |
+
3,
|
| 366 |
+
],
|
| 367 |
+
],
|
| 368 |
+
cache_examples="lazy",
|
| 369 |
+
)
|
| 370 |
+
|
| 371 |
+
|
| 372 |
+
demo.queue(api_open=False)
|
| 373 |
+
demo.launch(show_api=False)
|