Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -6,10 +6,6 @@ import numpy as np
|
|
6 |
import cv2
|
7 |
import gradio as gr
|
8 |
from torchvision import transforms
|
9 |
-
# from huggingface_hub import login
|
10 |
-
# login()
|
11 |
-
|
12 |
-
# controlnet_conditioning_scale = 1.0
|
13 |
|
14 |
controlnet = ControlNetModel.from_pretrained(
|
15 |
"briaai/ControlNet-Canny",
|
@@ -21,7 +17,7 @@ pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
|
|
21 |
controlnet=controlnet,
|
22 |
torch_dtype=torch.float16,
|
23 |
)
|
24 |
-
pipe.
|
25 |
|
26 |
low_threshold = 100
|
27 |
high_threshold = 200
|
@@ -47,14 +43,26 @@ def get_canny_filter(image):
|
|
47 |
canny_image = Image.fromarray(image)
|
48 |
return canny_image
|
49 |
|
50 |
-
def process(input_image, prompt, num_steps, controlnet_conditioning_scale):
|
|
|
|
|
51 |
# resize input_image to 1024x1024
|
52 |
input_image = resize_image(input_image)
|
53 |
|
54 |
canny_image = get_canny_filter(input_image)
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
return [canny_image,images[0]]
|
60 |
|
@@ -73,14 +81,16 @@ with block:
|
|
73 |
with gr.Column():
|
74 |
input_image = gr.Image(sources=None, type="pil") # None for upload, ctrl+v and webcam
|
75 |
prompt = gr.Textbox(label="Prompt")
|
|
|
76 |
num_steps = gr.Slider(label="Number of steps", minimum=25, maximum=100, value=50, step=1)
|
77 |
controlnet_conditioning_scale = gr.Slider(label="ControlNet conditioning scale", minimum=0.1, maximum=2.0, value=1.0, step=0.05)
|
|
|
78 |
run_button = gr.Button(value="Run")
|
79 |
|
80 |
|
81 |
with gr.Column():
|
82 |
result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery", columns=[2], height='auto')
|
83 |
-
ips = [input_image, prompt, num_steps, controlnet_conditioning_scale]
|
84 |
run_button.click(fn=process, inputs=ips, outputs=[result_gallery])
|
85 |
|
86 |
block.launch(debug = True)
|
|
|
6 |
import cv2
|
7 |
import gradio as gr
|
8 |
from torchvision import transforms
|
|
|
|
|
|
|
|
|
9 |
|
10 |
controlnet = ControlNetModel.from_pretrained(
|
11 |
"briaai/ControlNet-Canny",
|
|
|
17 |
controlnet=controlnet,
|
18 |
torch_dtype=torch.float16,
|
19 |
)
|
20 |
+
pipe.enable_xformers_memory_efficient_attention()
|
21 |
|
22 |
low_threshold = 100
|
23 |
high_threshold = 200
|
|
|
43 |
canny_image = Image.fromarray(image)
|
44 |
return canny_image
|
45 |
|
46 |
+
def process(input_image, prompt, negative_prompt, num_steps, controlnet_conditioning_scale, seed):
|
47 |
+
generator = torch.manual_seed(seed)
|
48 |
+
|
49 |
# resize input_image to 1024x1024
|
50 |
input_image = resize_image(input_image)
|
51 |
|
52 |
canny_image = get_canny_filter(input_image)
|
53 |
+
|
54 |
+
pipe.enable_freeu(b1=1.1, b2=1.1, s1=0.5, s2=0.7)
|
55 |
+
|
56 |
+
if negative_prompt != '':
|
57 |
+
images = pipe(
|
58 |
+
prompt, negative_prompt=negative_prompt, image=canny_image, num_inference_steps=num_steps, controlnet_conditioning_scale=float(controlnet_conditioning_scale),
|
59 |
+
generator=generator,
|
60 |
+
).images
|
61 |
+
else:
|
62 |
+
images = pipe(
|
63 |
+
prompt, force_zeros_for_empty_prompt=False, image=canny_image, num_inference_steps=num_steps, controlnet_conditioning_scale=float(controlnet_conditioning_scale),
|
64 |
+
generator=generator,
|
65 |
+
).images
|
66 |
|
67 |
return [canny_image,images[0]]
|
68 |
|
|
|
81 |
with gr.Column():
|
82 |
input_image = gr.Image(sources=None, type="pil") # None for upload, ctrl+v and webcam
|
83 |
prompt = gr.Textbox(label="Prompt")
|
84 |
+
negative_prompt = gr.Textbox(label="Negative prompt", value="Logo,Watermark,Text,Ugly,Morbid,Extra fingers,Poorly drawn hands,Mutation,Blurry,Extra limbs,Gross proportions,Missing arms,Mutated hands,Long neck,Duplicate,Mutilated,Mutilated hands,Poorly drawn face,Deformed,Bad anatomy,Cloned face,Malformed limbs,Missing legs,Too many fingers")
|
85 |
num_steps = gr.Slider(label="Number of steps", minimum=25, maximum=100, value=50, step=1)
|
86 |
controlnet_conditioning_scale = gr.Slider(label="ControlNet conditioning scale", minimum=0.1, maximum=2.0, value=1.0, step=0.05)
|
87 |
+
seed = gr.Slider(label="Seed", minimum=0, maximum=2147483647, step=1, randomize=True,)
|
88 |
run_button = gr.Button(value="Run")
|
89 |
|
90 |
|
91 |
with gr.Column():
|
92 |
result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery", columns=[2], height='auto')
|
93 |
+
ips = [input_image, prompt, negative_prompt, num_steps, controlnet_conditioning_scale, seed]
|
94 |
run_button.click(fn=process, inputs=ips, outputs=[result_gallery])
|
95 |
|
96 |
block.launch(debug = True)
|