Spaces:
Runtime error
Runtime error
RamAnanth1
commited on
Commit
·
c5a40b1
1
Parent(s):
95af500
Update app.py
Browse files
app.py
CHANGED
@@ -21,7 +21,12 @@ model.load_state_dict(load_state_dict(cached_download(
|
|
21 |
), location='cpu'))
|
22 |
ddim_sampler = DDIMSampler(model)
|
23 |
|
24 |
-
def process(input_image, prompt, a_prompt, n_prompt, num_samples, image_resolution, ddim_steps, scale, seed, eta, low_threshold, high_threshold):
|
|
|
|
|
|
|
|
|
|
|
25 |
with torch.no_grad():
|
26 |
img = resize_image(HWC3(input_image), image_resolution)
|
27 |
H, W, C = img.shape
|
@@ -51,12 +56,16 @@ def process(input_image, prompt, a_prompt, n_prompt, num_samples, image_resoluti
|
|
51 |
|
52 |
|
53 |
block = gr.Blocks().queue()
|
|
|
|
|
|
|
|
|
54 |
with block:
|
55 |
-
|
56 |
-
gr.Markdown("## Control Stable Diffusion with Canny Edge Maps")
|
57 |
with gr.Row():
|
58 |
with gr.Column():
|
59 |
input_image = gr.Image(source='upload', type="numpy")
|
|
|
60 |
prompt = gr.Textbox(label="Prompt")
|
61 |
run_button = gr.Button(label="Run")
|
62 |
with gr.Accordion("Advanced options", open=False):
|
@@ -73,10 +82,10 @@ with block:
|
|
73 |
value='longbody, lowres, bad anatomy, bad hands, missing fingers, pubic hair,extra digit, fewer digits, cropped, worst quality, low quality')
|
74 |
with gr.Column():
|
75 |
result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery").style(grid=2, height='auto')
|
76 |
-
ips = [input_image, prompt, a_prompt, n_prompt, num_samples, image_resolution, ddim_steps, scale, seed, eta, low_threshold, high_threshold]
|
77 |
run_button.click(fn=process, inputs=ips, outputs=[result_gallery])
|
78 |
|
79 |
-
examples = gr.Examples(examples=[["bird.png", "bird"]],inputs = [input_image, prompt], outputs = [result_gallery])
|
80 |
|
81 |
|
82 |
block.launch(debug = True)
|
|
|
21 |
), location='cpu'))
|
22 |
ddim_sampler = DDIMSampler(model)
|
23 |
|
24 |
+
def process(input_image, prompt, input_control, a_prompt, n_prompt, num_samples, image_resolution, ddim_steps, scale, seed, eta, low_threshold, high_threshold):
|
25 |
+
# TODO: Add other control tasks
|
26 |
+
return process_canny(input_image, prompt, a_prompt, n_prompt, num_samples, image_resolution, ddim_steps, scale, seed, eta, low_threshold, high_threshold)
|
27 |
+
|
28 |
+
|
29 |
+
def process_canny(input_image, prompt, a_prompt, n_prompt, num_samples, image_resolution, ddim_steps, scale, seed, eta, low_threshold, high_threshold):
|
30 |
with torch.no_grad():
|
31 |
img = resize_image(HWC3(input_image), image_resolution)
|
32 |
H, W, C = img.shape
|
|
|
56 |
|
57 |
|
58 |
block = gr.Blocks().queue()
|
59 |
+
control_task_list = [
|
60 |
+
"Canny Edge Map",
|
61 |
+
"Human Pose"
|
62 |
+
]
|
63 |
with block:
|
64 |
+
gr.Markdown("## Adding Conditional Control to Text-to-Image Diffusion Models")
|
|
|
65 |
with gr.Row():
|
66 |
with gr.Column():
|
67 |
input_image = gr.Image(source='upload', type="numpy")
|
68 |
+
input_control = gr.Dropdown(control_list, value="Canny Edge Map", label="Control Task"),
|
69 |
prompt = gr.Textbox(label="Prompt")
|
70 |
run_button = gr.Button(label="Run")
|
71 |
with gr.Accordion("Advanced options", open=False):
|
|
|
82 |
value='longbody, lowres, bad anatomy, bad hands, missing fingers, pubic hair,extra digit, fewer digits, cropped, worst quality, low quality')
|
83 |
with gr.Column():
|
84 |
result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery").style(grid=2, height='auto')
|
85 |
+
ips = [input_image, prompt, input_control, a_prompt, n_prompt, num_samples, image_resolution, ddim_steps, scale, seed, eta, low_threshold, high_threshold]
|
86 |
run_button.click(fn=process, inputs=ips, outputs=[result_gallery])
|
87 |
|
88 |
+
examples = gr.Examples(examples=[["bird.png", "bird","Canny Edge Map"]],inputs = [input_image, prompt, input_control], outputs = [result_gallery])
|
89 |
|
90 |
|
91 |
block.launch(debug = True)
|