Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,19 +14,11 @@ from diffusers.models import SD3ControlNetModel, SD3MultiControlNetModel
|
|
| 14 |
from diffusers.utils import load_image
|
| 15 |
|
| 16 |
# load pipeline
|
|
|
|
|
|
|
| 17 |
controlnet_canny = SD3ControlNetModel.from_pretrained("InstantX/SD3-Controlnet-Canny")
|
| 18 |
controlnet_tile = SD3ControlNetModel.from_pretrained("InstantX/SD3-Controlnet-Tile")
|
| 19 |
|
| 20 |
-
pipe_canny = StableDiffusion3ControlNetPipeline.from_pretrained(
|
| 21 |
-
"stabilityai/stable-diffusion-3-medium-diffusers",
|
| 22 |
-
controlnet=controlnet_canny
|
| 23 |
-
)
|
| 24 |
-
|
| 25 |
-
pipe_tile = StableDiffusion3ControlNetPipeline.from_pretrained(
|
| 26 |
-
"stabilityai/stable-diffusion-3-medium-diffusers",
|
| 27 |
-
controlnet=controlnet_tile
|
| 28 |
-
)
|
| 29 |
-
|
| 30 |
def resize_image(input_path, output_path, target_height):
|
| 31 |
# Open the input image
|
| 32 |
img = Image.open(input_path)
|
|
@@ -46,8 +38,20 @@ def resize_image(input_path, output_path, target_height):
|
|
| 46 |
|
| 47 |
return output_path, new_width, target_height
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
@spaces.GPU(duration=90)
|
| 50 |
-
def
|
| 51 |
|
| 52 |
n_prompt = 'NSFW, nude, naked, porn, ugly'
|
| 53 |
|
|
@@ -132,7 +136,11 @@ with gr.Blocks(css=css) as demo:
|
|
| 132 |
|
| 133 |
|
| 134 |
submit_canny_btn.click(
|
| 135 |
-
fn =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
inputs = [image_in, prompt, control_type, inference_steps, guidance_scale, control_weight],
|
| 137 |
outputs = [result, canny_used],
|
| 138 |
show_api=False
|
|
|
|
| 14 |
from diffusers.utils import load_image
|
| 15 |
|
| 16 |
# load pipeline
|
| 17 |
+
global pipe_canny
|
| 18 |
+
global pipe_tile
|
| 19 |
controlnet_canny = SD3ControlNetModel.from_pretrained("InstantX/SD3-Controlnet-Canny")
|
| 20 |
controlnet_tile = SD3ControlNetModel.from_pretrained("InstantX/SD3-Controlnet-Tile")
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
def resize_image(input_path, output_path, target_height):
|
| 23 |
# Open the input image
|
| 24 |
img = Image.open(input_path)
|
|
|
|
| 38 |
|
| 39 |
return output_path, new_width, target_height
|
| 40 |
|
| 41 |
+
def load_pipeline(control_type):
|
| 42 |
+
if control_type == "canny":
|
| 43 |
+
pipe_canny = StableDiffusion3ControlNetPipeline.from_pretrained(
|
| 44 |
+
"stabilityai/stable-diffusion-3-medium-diffusers",
|
| 45 |
+
controlnet=controlnet_canny
|
| 46 |
+
)
|
| 47 |
+
elif control_type == "tile":
|
| 48 |
+
pipe_tile = StableDiffusion3ControlNetPipeline.from_pretrained(
|
| 49 |
+
"stabilityai/stable-diffusion-3-medium-diffusers",
|
| 50 |
+
controlnet=controlnet_tile
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
@spaces.GPU(duration=90)
|
| 54 |
+
def infer(image_in, prompt, control_type, inference_steps, guidance_scale, control_weight, progress=gr.Progress(track_tqdm=True)):
|
| 55 |
|
| 56 |
n_prompt = 'NSFW, nude, naked, porn, ugly'
|
| 57 |
|
|
|
|
| 136 |
|
| 137 |
|
| 138 |
submit_canny_btn.click(
|
| 139 |
+
fn = load_pipeline,
|
| 140 |
+
inputs = [control_type],
|
| 141 |
+
outputs = None
|
| 142 |
+
).then(
|
| 143 |
+
fn = infer,
|
| 144 |
inputs = [image_in, prompt, control_type, inference_steps, guidance_scale, control_weight],
|
| 145 |
outputs = [result, canny_used],
|
| 146 |
show_api=False
|