Spaces:
Running
Running
Sean Powell commited on
Commit ·
0cdb495
1
Parent(s): a5222e6
Implement a HF handler.
Browse files- handler.py +28 -0
handler.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from utils import pipes, tiling, wallpaper, images
|
| 2 |
+
|
| 3 |
+
desired_output_width = 1024
|
| 4 |
+
inference_steps = 25
|
| 5 |
+
img2img_strength = 0.5
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class EndpointHandler:
|
| 9 |
+
def __init__(self, path=""):
|
| 10 |
+
self.sdxl_pipe = pipes.create_stable_diffusion_xl_pipeline()
|
| 11 |
+
self.sdxl_img2img_pipe = pipes.create_stable_diffusion_xl_img2img_pipe()
|
| 12 |
+
|
| 13 |
+
def __call__(self, data):
|
| 14 |
+
prompt = data.pop("inputs", data)
|
| 15 |
+
|
| 16 |
+
original_image_size = tiling.compute_input_tile_width_for_desired_output(desired_output_width)
|
| 17 |
+
|
| 18 |
+
original_image = self.sdxl_pipe(prompt=prompt, num_inference_steps=inference_steps, width=original_image_size,
|
| 19 |
+
height=original_image_size).images[0]
|
| 20 |
+
inner_rotated_tile = images.extract_inner_rotated_tile_from_image(original_image)
|
| 21 |
+
|
| 22 |
+
tileable_image = \
|
| 23 |
+
self.sdxl_img2img_pipe(prompt, image=inner_rotated_tile.convert("RGB"), num_inference_steps=inference_steps,
|
| 24 |
+
strength=img2img_strength).images[
|
| 25 |
+
0]
|
| 26 |
+
half_drop = wallpaper.convert_tile_to_half_drop(tileable_image)
|
| 27 |
+
|
| 28 |
+
return half_drop
|