Spaces:
Running
on
Zero
Running
on
Zero
Update app_canny.py
Browse files- app_canny.py +136 -136
app_canny.py
CHANGED
@@ -1,136 +1,136 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import random
|
3 |
-
|
4 |
-
|
5 |
-
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
6 |
-
if randomize_seed:
|
7 |
-
seed = random.randint(0, 100000000)
|
8 |
-
return seed
|
9 |
-
|
10 |
-
|
11 |
-
examples = [
|
12 |
-
[
|
13 |
-
"condition/example/t2i/multigen/doll.jpg",
|
14 |
-
"A stuffed animal wearing a mask and a leash, sitting on a blanket",
|
15 |
-
"(512, 512)"
|
16 |
-
],
|
17 |
-
[
|
18 |
-
"condition/example/t2i/multigen/girl.jpg",
|
19 |
-
"An anime style girl with blue hair", "(512, 512)"
|
20 |
-
],
|
21 |
-
[
|
22 |
-
"condition/example/t2i/multi_resolution/bird.jpg", "colorful bird",
|
23 |
-
"(921, 564)"
|
24 |
-
],
|
25 |
-
]
|
26 |
-
|
27 |
-
|
28 |
-
def create_demo(process):
|
29 |
-
with gr.Blocks() as demo:
|
30 |
-
with gr.Row():
|
31 |
-
with gr.Column():
|
32 |
-
image = gr.Image()
|
33 |
-
prompt = gr.Textbox(label="Prompt")
|
34 |
-
run_button = gr.Button("Run")
|
35 |
-
with gr.Accordion("Advanced options", open=False):
|
36 |
-
canny_low_threshold = gr.Slider(
|
37 |
-
label="Canny low threshold",
|
38 |
-
minimum=0,
|
39 |
-
maximum=
|
40 |
-
value=100,
|
41 |
-
step=50)
|
42 |
-
canny_high_threshold = gr.Slider(
|
43 |
-
label="Canny high threshold",
|
44 |
-
minimum=0,
|
45 |
-
maximum=
|
46 |
-
value=200,
|
47 |
-
step=50)
|
48 |
-
cfg_scale = gr.Slider(label="Guidance scale",
|
49 |
-
minimum=0.1,
|
50 |
-
maximum=30.0,
|
51 |
-
value=4,
|
52 |
-
step=0.1)
|
53 |
-
relolution = gr.Slider(label="(H, W)",
|
54 |
-
minimum=384,
|
55 |
-
maximum=768,
|
56 |
-
value=512,
|
57 |
-
step=16)
|
58 |
-
top_k = gr.Slider(minimum=1,
|
59 |
-
maximum=16384,
|
60 |
-
step=1,
|
61 |
-
value=2000,
|
62 |
-
label='Top-K')
|
63 |
-
top_p = gr.Slider(minimum=0.,
|
64 |
-
maximum=1.0,
|
65 |
-
step=0.1,
|
66 |
-
value=1.0,
|
67 |
-
label="Top-P")
|
68 |
-
temperature = gr.Slider(minimum=0.,
|
69 |
-
maximum=1.0,
|
70 |
-
step=0.1,
|
71 |
-
value=1.0,
|
72 |
-
label='Temperature')
|
73 |
-
seed = gr.Slider(label="Seed",
|
74 |
-
minimum=0,
|
75 |
-
maximum=100000000,
|
76 |
-
step=1,
|
77 |
-
value=0)
|
78 |
-
randomize_seed = gr.Checkbox(label="Randomize seed",
|
79 |
-
value=True)
|
80 |
-
with gr.Column():
|
81 |
-
result = gr.Gallery(label="Output",
|
82 |
-
show_label=False,
|
83 |
-
height='800px',
|
84 |
-
columns=2,
|
85 |
-
object_fit="scale-down")
|
86 |
-
gr.Examples(
|
87 |
-
examples=examples,
|
88 |
-
inputs=[
|
89 |
-
image,
|
90 |
-
prompt,
|
91 |
-
relolution,
|
92 |
-
]
|
93 |
-
)
|
94 |
-
inputs = [
|
95 |
-
image,
|
96 |
-
prompt,
|
97 |
-
cfg_scale,
|
98 |
-
temperature,
|
99 |
-
top_k,
|
100 |
-
top_p,
|
101 |
-
seed,
|
102 |
-
canny_low_threshold,
|
103 |
-
canny_high_threshold,
|
104 |
-
]
|
105 |
-
# prompt.submit(
|
106 |
-
# fn=randomize_seed_fn,
|
107 |
-
# inputs=[seed, randomize_seed],
|
108 |
-
# outputs=seed,
|
109 |
-
# queue=False,
|
110 |
-
# api_name=False,
|
111 |
-
# ).then(
|
112 |
-
# fn=process,
|
113 |
-
# inputs=inputs,
|
114 |
-
# outputs=result,
|
115 |
-
# api_name=False,
|
116 |
-
# )
|
117 |
-
run_button.click(
|
118 |
-
fn=randomize_seed_fn,
|
119 |
-
inputs=[seed, randomize_seed],
|
120 |
-
outputs=seed,
|
121 |
-
queue=False,
|
122 |
-
api_name=False,
|
123 |
-
).then(
|
124 |
-
fn=process,
|
125 |
-
inputs=inputs,
|
126 |
-
outputs=result,
|
127 |
-
api_name="canny",
|
128 |
-
)
|
129 |
-
return demo
|
130 |
-
|
131 |
-
|
132 |
-
if __name__ == "__main__":
|
133 |
-
from model import Model
|
134 |
-
model = Model()
|
135 |
-
demo = create_demo(model.process_canny)
|
136 |
-
demo.queue().launch(share=False, server_name="0.0.0.0")
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
|
4 |
+
|
5 |
+
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
6 |
+
if randomize_seed:
|
7 |
+
seed = random.randint(0, 100000000)
|
8 |
+
return seed
|
9 |
+
|
10 |
+
|
11 |
+
examples = [
|
12 |
+
[
|
13 |
+
"condition/example/t2i/multigen/doll.jpg",
|
14 |
+
"A stuffed animal wearing a mask and a leash, sitting on a blanket",
|
15 |
+
"(512, 512)"
|
16 |
+
],
|
17 |
+
[
|
18 |
+
"condition/example/t2i/multigen/girl.jpg",
|
19 |
+
"An anime style girl with blue hair", "(512, 512)"
|
20 |
+
],
|
21 |
+
[
|
22 |
+
"condition/example/t2i/multi_resolution/bird.jpg", "colorful bird",
|
23 |
+
"(921, 564)"
|
24 |
+
],
|
25 |
+
]
|
26 |
+
|
27 |
+
|
28 |
+
def create_demo(process):
|
29 |
+
with gr.Blocks() as demo:
|
30 |
+
with gr.Row():
|
31 |
+
with gr.Column():
|
32 |
+
image = gr.Image()
|
33 |
+
prompt = gr.Textbox(label="Prompt")
|
34 |
+
run_button = gr.Button("Run")
|
35 |
+
with gr.Accordion("Advanced options", open=False):
|
36 |
+
canny_low_threshold = gr.Slider(
|
37 |
+
label="Canny low threshold",
|
38 |
+
minimum=0,
|
39 |
+
maximum=255,
|
40 |
+
value=100,
|
41 |
+
step=50)
|
42 |
+
canny_high_threshold = gr.Slider(
|
43 |
+
label="Canny high threshold",
|
44 |
+
minimum=0,
|
45 |
+
maximum=255,
|
46 |
+
value=200,
|
47 |
+
step=50)
|
48 |
+
cfg_scale = gr.Slider(label="Guidance scale",
|
49 |
+
minimum=0.1,
|
50 |
+
maximum=30.0,
|
51 |
+
value=4,
|
52 |
+
step=0.1)
|
53 |
+
relolution = gr.Slider(label="(H, W)",
|
54 |
+
minimum=384,
|
55 |
+
maximum=768,
|
56 |
+
value=512,
|
57 |
+
step=16)
|
58 |
+
top_k = gr.Slider(minimum=1,
|
59 |
+
maximum=16384,
|
60 |
+
step=1,
|
61 |
+
value=2000,
|
62 |
+
label='Top-K')
|
63 |
+
top_p = gr.Slider(minimum=0.,
|
64 |
+
maximum=1.0,
|
65 |
+
step=0.1,
|
66 |
+
value=1.0,
|
67 |
+
label="Top-P")
|
68 |
+
temperature = gr.Slider(minimum=0.,
|
69 |
+
maximum=1.0,
|
70 |
+
step=0.1,
|
71 |
+
value=1.0,
|
72 |
+
label='Temperature')
|
73 |
+
seed = gr.Slider(label="Seed",
|
74 |
+
minimum=0,
|
75 |
+
maximum=100000000,
|
76 |
+
step=1,
|
77 |
+
value=0)
|
78 |
+
randomize_seed = gr.Checkbox(label="Randomize seed",
|
79 |
+
value=True)
|
80 |
+
with gr.Column():
|
81 |
+
result = gr.Gallery(label="Output",
|
82 |
+
show_label=False,
|
83 |
+
height='800px',
|
84 |
+
columns=2,
|
85 |
+
object_fit="scale-down")
|
86 |
+
gr.Examples(
|
87 |
+
examples=examples,
|
88 |
+
inputs=[
|
89 |
+
image,
|
90 |
+
prompt,
|
91 |
+
relolution,
|
92 |
+
]
|
93 |
+
)
|
94 |
+
inputs = [
|
95 |
+
image,
|
96 |
+
prompt,
|
97 |
+
cfg_scale,
|
98 |
+
temperature,
|
99 |
+
top_k,
|
100 |
+
top_p,
|
101 |
+
seed,
|
102 |
+
canny_low_threshold,
|
103 |
+
canny_high_threshold,
|
104 |
+
]
|
105 |
+
# prompt.submit(
|
106 |
+
# fn=randomize_seed_fn,
|
107 |
+
# inputs=[seed, randomize_seed],
|
108 |
+
# outputs=seed,
|
109 |
+
# queue=False,
|
110 |
+
# api_name=False,
|
111 |
+
# ).then(
|
112 |
+
# fn=process,
|
113 |
+
# inputs=inputs,
|
114 |
+
# outputs=result,
|
115 |
+
# api_name=False,
|
116 |
+
# )
|
117 |
+
run_button.click(
|
118 |
+
fn=randomize_seed_fn,
|
119 |
+
inputs=[seed, randomize_seed],
|
120 |
+
outputs=seed,
|
121 |
+
queue=False,
|
122 |
+
api_name=False,
|
123 |
+
).then(
|
124 |
+
fn=process,
|
125 |
+
inputs=inputs,
|
126 |
+
outputs=result,
|
127 |
+
api_name="canny",
|
128 |
+
)
|
129 |
+
return demo
|
130 |
+
|
131 |
+
|
132 |
+
if __name__ == "__main__":
|
133 |
+
from model import Model
|
134 |
+
model = Model()
|
135 |
+
demo = create_demo(model.process_canny)
|
136 |
+
demo.queue().launch(share=False, server_name="0.0.0.0")
|