Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
274c3ad
1
Parent(s):
6fe1b7e
fixed control_image
Browse files- app.py +6 -6
- pipeline/mod_controlnet_tile_sr_sdxl.py +20 -0
- pipeline/util.py +0 -21
app.py
CHANGED
|
@@ -3,11 +3,10 @@ import spaces
|
|
| 3 |
from diffusers import ControlNetUnionModel, AutoencoderKL
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
-
from pipeline.mod_controlnet_tile_sr_sdxl import StableDiffusionXLControlNetTileSRPipeline
|
| 7 |
from pipeline.util import (
|
| 8 |
SAMPLERS,
|
| 9 |
Platinum,
|
| 10 |
-
calculate_overlap,
|
| 11 |
create_hdr_effect,
|
| 12 |
progressive_upscale,
|
| 13 |
select_scheduler,
|
|
@@ -60,8 +59,9 @@ def predict(
|
|
| 60 |
print(f"Current resolution: H:{original_height} x W:{original_width}")
|
| 61 |
|
| 62 |
# Pre-upscale image for tiling
|
| 63 |
-
control_image =
|
| 64 |
-
|
|
|
|
| 65 |
|
| 66 |
# Update target height and width
|
| 67 |
target_height = control_image.height
|
|
@@ -75,8 +75,8 @@ def predict(
|
|
| 75 |
# Image generation
|
| 76 |
print("Diffusion kicking in... almost done, coffee's on you!")
|
| 77 |
image = pipe(
|
| 78 |
-
image=
|
| 79 |
-
control_image=
|
| 80 |
control_mode=[6],
|
| 81 |
controlnet_conditioning_scale=float(controlnet_strength),
|
| 82 |
prompt=prompt,
|
|
|
|
| 3 |
from diffusers import ControlNetUnionModel, AutoencoderKL
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
+
from pipeline.mod_controlnet_tile_sr_sdxl import StableDiffusionXLControlNetTileSRPipeline, calculate_overlap
|
| 7 |
from pipeline.util import (
|
| 8 |
SAMPLERS,
|
| 9 |
Platinum,
|
|
|
|
| 10 |
create_hdr_effect,
|
| 11 |
progressive_upscale,
|
| 12 |
select_scheduler,
|
|
|
|
| 59 |
print(f"Current resolution: H:{original_height} x W:{original_width}")
|
| 60 |
|
| 61 |
# Pre-upscale image for tiling
|
| 62 |
+
control_image = create_hdr_effect(image, hdr)
|
| 63 |
+
image = progressive_upscale(image, resolution)
|
| 64 |
+
image = create_hdr_effect(image, hdr)
|
| 65 |
|
| 66 |
# Update target height and width
|
| 67 |
target_height = control_image.height
|
|
|
|
| 75 |
# Image generation
|
| 76 |
print("Diffusion kicking in... almost done, coffee's on you!")
|
| 77 |
image = pipe(
|
| 78 |
+
image=image,
|
| 79 |
+
control_image=control_image,
|
| 80 |
control_mode=[6],
|
| 81 |
controlnet_conditioning_scale=float(controlnet_strength),
|
| 82 |
prompt=prompt,
|
pipeline/mod_controlnet_tile_sr_sdxl.py
CHANGED
|
@@ -264,6 +264,26 @@ def retrieve_latents(
|
|
| 264 |
else:
|
| 265 |
raise AttributeError("Could not access latents of provided encoder_output")
|
| 266 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
class TileWeightingMethod(Enum):
|
| 268 |
"""Mode in which the tile weights will be generated"""
|
| 269 |
|
|
|
|
| 264 |
else:
|
| 265 |
raise AttributeError("Could not access latents of provided encoder_output")
|
| 266 |
|
| 267 |
+
def calculate_overlap(width, height, base_overlap=128):
|
| 268 |
+
"""
|
| 269 |
+
Calculates dynamic overlap based on the image's aspect ratio.
|
| 270 |
+
|
| 271 |
+
Args:
|
| 272 |
+
width (int): Width of the image in pixels.
|
| 273 |
+
height (int): Height of the image in pixels.
|
| 274 |
+
base_overlap (int, optional): Base overlap value in pixels. Defaults to 128.
|
| 275 |
+
|
| 276 |
+
Returns:
|
| 277 |
+
tuple: A tuple containing:
|
| 278 |
+
- row_overlap (int): Overlap between tiles in consecutive rows.
|
| 279 |
+
- col_overlap (int): Overlap between tiles in consecutive columns.
|
| 280 |
+
"""
|
| 281 |
+
ratio = height / width
|
| 282 |
+
if ratio < 1: # Image is wider than tall
|
| 283 |
+
return base_overlap // 2, base_overlap
|
| 284 |
+
else: # Image is taller than wide
|
| 285 |
+
return base_overlap, base_overlap * 2
|
| 286 |
+
|
| 287 |
class TileWeightingMethod(Enum):
|
| 288 |
"""Mode in which the tile weights will be generated"""
|
| 289 |
|
pipeline/util.py
CHANGED
|
@@ -157,27 +157,6 @@ def select_scheduler(pipe, selected_sampler):
|
|
| 157 |
return scheduler.from_config(config, **add_kwargs)
|
| 158 |
|
| 159 |
|
| 160 |
-
def calculate_overlap(width, height, base_overlap=128):
|
| 161 |
-
"""
|
| 162 |
-
Calculates dynamic overlap based on the image's aspect ratio.
|
| 163 |
-
|
| 164 |
-
Args:
|
| 165 |
-
width (int): Width of the image in pixels.
|
| 166 |
-
height (int): Height of the image in pixels.
|
| 167 |
-
base_overlap (int, optional): Base overlap value in pixels. Defaults to 128.
|
| 168 |
-
|
| 169 |
-
Returns:
|
| 170 |
-
tuple: A tuple containing:
|
| 171 |
-
- row_overlap (int): Overlap between tiles in consecutive rows.
|
| 172 |
-
- col_overlap (int): Overlap between tiles in consecutive columns.
|
| 173 |
-
"""
|
| 174 |
-
ratio = height / width
|
| 175 |
-
if ratio < 1: # Image is wider than tall
|
| 176 |
-
return base_overlap // 2, base_overlap
|
| 177 |
-
else: # Image is taller than wide
|
| 178 |
-
return base_overlap, base_overlap * 2
|
| 179 |
-
|
| 180 |
-
|
| 181 |
# This function was copied and adapted from https://huggingface.co/spaces/gokaygokay/TileUpscalerV2, licensed under Apache 2.0.
|
| 182 |
def progressive_upscale(input_image, target_resolution, steps=3):
|
| 183 |
"""
|
|
|
|
| 157 |
return scheduler.from_config(config, **add_kwargs)
|
| 158 |
|
| 159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
# This function was copied and adapted from https://huggingface.co/spaces/gokaygokay/TileUpscalerV2, licensed under Apache 2.0.
|
| 161 |
def progressive_upscale(input_image, target_resolution, steps=3):
|
| 162 |
"""
|