-
Notifications
You must be signed in to change notification settings - Fork 209
/
demo.py
173 lines (170 loc) · 8 KB
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import gradio as gr
def create_demo_sketch(run):
cond_name = gr.State(value='sketch')
with gr.Blocks() as demo:
with gr.Row():
gr.Markdown('## Control Stable Diffusion-XL with Sketch Maps')
with gr.Row():
with gr.Column():
input_image = gr.Image(source='upload', type='numpy')
prompt = gr.Textbox(label='Prompt')
run_button = gr.Button(label='Run')
in_type = gr.Radio(
choices=["Image", "Sketch"],
label=f"Input type for Sketch",
interactive=True,
value="Image",
)
with gr.Accordion('Advanced options', open=False):
con_strength = gr.Slider(label='Control Strength',
minimum=0.0,
maximum=1.0,
value=1.0,
step=0.1)
ddim_steps = gr.Slider(label='Steps',
minimum=1,
maximum=100,
value=20,
step=1)
scale = gr.Slider(label='Guidance Scale',
minimum=0.1,
maximum=30.0,
value=7.5,
step=0.1)
seed = gr.Slider(label='Seed',
minimum=-1,
maximum=2147483647,
step=1,
randomize=True)
a_prompt = gr.Textbox(
label='Added Prompt',
value='in real world, high quality')
n_prompt = gr.Textbox(
label='Negative Prompt',
value='extra digit, fewer digits, cropped, worst quality, low quality'
)
with gr.Column():
result_gallery = gr.Gallery(label='Output',
show_label=False,
elem_id='gallery').style(
grid=2, height='auto')
ips = [
input_image, in_type, prompt, a_prompt, n_prompt,
ddim_steps, scale, seed, cond_name, con_strength
]
run_button.click(fn=run,
inputs=ips,
outputs=[result_gallery],
api_name='sketch')
return demo
def create_demo_canny(run):
cond_name = gr.State(value='canny')
with gr.Blocks() as demo:
with gr.Row():
gr.Markdown('## Control Stable Diffusion-XL with Canny Maps')
with gr.Row():
with gr.Column():
input_image = gr.Image(source='upload', type='numpy')
prompt = gr.Textbox(label='Prompt')
run_button = gr.Button(label='Run')
in_type = gr.Radio(
choices=["Image", "Canny"],
label=f"Input type for Canny",
interactive=True,
value="Image",
)
with gr.Accordion('Advanced options', open=False):
con_strength = gr.Slider(label='Control Strength',
minimum=0.0,
maximum=1.0,
value=1.0,
step=0.1)
ddim_steps = gr.Slider(label='Steps',
minimum=1,
maximum=100,
value=20,
step=1)
scale = gr.Slider(label='Guidance Scale',
minimum=0.1,
maximum=30.0,
value=7.5,
step=0.1)
seed = gr.Slider(label='Seed',
minimum=-1,
maximum=2147483647,
step=1,
randomize=True)
a_prompt = gr.Textbox(
label='Added Prompt',
value='in real world, high quality')
n_prompt = gr.Textbox(
label='Negative Prompt',
value='extra digit, fewer digits, cropped, worst quality, low quality'
)
with gr.Column():
result_gallery = gr.Gallery(label='Output',
show_label=False,
elem_id='gallery').style(
grid=2, height='auto')
ips = [
input_image, in_type, prompt, a_prompt, n_prompt,
ddim_steps, scale, seed, cond_name, con_strength
]
run_button.click(fn=run,
inputs=ips,
outputs=[result_gallery],
api_name='canny')
return demo
def create_demo_pose(run):
cond_name = gr.State(value='openpose')
in_type = gr.State(value='Image')
with gr.Blocks() as demo:
with gr.Row():
gr.Markdown('## Control Stable Diffusion-XL with Keypoint Maps')
with gr.Row():
with gr.Column():
input_image = gr.Image(source='upload', type='numpy')
prompt = gr.Textbox(label='Prompt')
run_button = gr.Button(label='Run')
with gr.Accordion('Advanced options', open=False):
con_strength = gr.Slider(label='Control Strength',
minimum=0.0,
maximum=1.0,
value=1.0,
step=0.1)
ddim_steps = gr.Slider(label='Steps',
minimum=1,
maximum=100,
value=20,
step=1)
scale = gr.Slider(label='Guidance Scale',
minimum=0.1,
maximum=30.0,
value=7.5,
step=0.1)
seed = gr.Slider(label='Seed',
minimum=-1,
maximum=2147483647,
step=1,
randomize=True)
a_prompt = gr.Textbox(
label='Added Prompt',
value='in real world, high quality')
n_prompt = gr.Textbox(
label='Negative Prompt',
value='extra digit, fewer digits, cropped, worst quality, low quality'
)
with gr.Column():
result_gallery = gr.Gallery(label='Output',
show_label=False,
elem_id='gallery').style(
grid=2, height='auto')
ips = [
input_image, in_type, prompt, a_prompt, n_prompt,
ddim_steps, scale, seed, cond_name, con_strength
]
run_button.click(fn=run,
inputs=ips,
outputs=[result_gallery],
api_name='openpose')
return demo