Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -40,15 +40,16 @@ def resize_image(input_path, output_path, 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 |
-
|
| 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)):
|
|
@@ -56,7 +57,7 @@ def infer(image_in, prompt, control_type, inference_steps, guidance_scale, contr
|
|
| 56 |
n_prompt = 'NSFW, nude, naked, porn, ugly'
|
| 57 |
|
| 58 |
if control_type == "canny":
|
| 59 |
-
pipe = pipe_canny
|
| 60 |
pipe.to("cuda", torch.float16)
|
| 61 |
# Canny preprocessing
|
| 62 |
image_to_canny = load_image(image_in)
|
|
@@ -69,7 +70,7 @@ def infer(image_in, prompt, control_type, inference_steps, guidance_scale, contr
|
|
| 69 |
control_image = image_to_canny
|
| 70 |
|
| 71 |
elif control_type == "tile":
|
| 72 |
-
pipe = pipe_tile
|
| 73 |
pipe.to("cuda", torch.float16)
|
| 74 |
control_image = load_image(image_in)
|
| 75 |
|
|
@@ -130,15 +131,17 @@ with gr.Blocks(css=css) as demo:
|
|
| 130 |
control_weight = gr.Slider(label="Control Weight", minimum=0.0, maximum=1.0, step=0.01, value=0.7)
|
| 131 |
|
| 132 |
submit_canny_btn = gr.Button("Submit")
|
|
|
|
| 133 |
with gr.Column():
|
| 134 |
result = gr.Image(label="Result")
|
| 135 |
canny_used = gr.Image(label="Preprocessed Canny", visible=False)
|
|
|
|
| 136 |
|
| 137 |
|
| 138 |
submit_canny_btn.click(
|
| 139 |
fn = load_pipeline,
|
| 140 |
inputs = [control_type],
|
| 141 |
-
outputs =
|
| 142 |
).then(
|
| 143 |
fn = infer,
|
| 144 |
inputs = [image_in, prompt, control_type, inference_steps, guidance_scale, control_weight],
|
|
|
|
| 40 |
|
| 41 |
def load_pipeline(control_type):
|
| 42 |
if control_type == "canny":
|
| 43 |
+
global pipe_canny = StableDiffusion3ControlNetPipeline.from_pretrained(
|
| 44 |
"stabilityai/stable-diffusion-3-medium-diffusers",
|
| 45 |
controlnet=controlnet_canny
|
| 46 |
)
|
| 47 |
elif control_type == "tile":
|
| 48 |
+
global pipe_tile = StableDiffusion3ControlNetPipeline.from_pretrained(
|
| 49 |
"stabilityai/stable-diffusion-3-medium-diffusers",
|
| 50 |
controlnet=controlnet_tile
|
| 51 |
)
|
| 52 |
+
return gr.update(value="pipeline ready", visible=True)
|
| 53 |
|
| 54 |
@spaces.GPU(duration=90)
|
| 55 |
def infer(image_in, prompt, control_type, inference_steps, guidance_scale, control_weight, progress=gr.Progress(track_tqdm=True)):
|
|
|
|
| 57 |
n_prompt = 'NSFW, nude, naked, porn, ugly'
|
| 58 |
|
| 59 |
if control_type == "canny":
|
| 60 |
+
global pipe = pipe_canny
|
| 61 |
pipe.to("cuda", torch.float16)
|
| 62 |
# Canny preprocessing
|
| 63 |
image_to_canny = load_image(image_in)
|
|
|
|
| 70 |
control_image = image_to_canny
|
| 71 |
|
| 72 |
elif control_type == "tile":
|
| 73 |
+
global pipe = pipe_tile
|
| 74 |
pipe.to("cuda", torch.float16)
|
| 75 |
control_image = load_image(image_in)
|
| 76 |
|
|
|
|
| 131 |
control_weight = gr.Slider(label="Control Weight", minimum=0.0, maximum=1.0, step=0.01, value=0.7)
|
| 132 |
|
| 133 |
submit_canny_btn = gr.Button("Submit")
|
| 134 |
+
models = gr.Textbox(visible=False)
|
| 135 |
with gr.Column():
|
| 136 |
result = gr.Image(label="Result")
|
| 137 |
canny_used = gr.Image(label="Preprocessed Canny", visible=False)
|
| 138 |
+
|
| 139 |
|
| 140 |
|
| 141 |
submit_canny_btn.click(
|
| 142 |
fn = load_pipeline,
|
| 143 |
inputs = [control_type],
|
| 144 |
+
outputs = [models]
|
| 145 |
).then(
|
| 146 |
fn = infer,
|
| 147 |
inputs = [image_in, prompt, control_type, inference_steps, guidance_scale, control_weight],
|