lixiang46
commited on
Commit
•
e9f3ef9
1
Parent(s):
78697e3
split
Browse files
app.py
CHANGED
@@ -75,9 +75,8 @@ MAX_SEED = np.iinfo(np.int32).max
|
|
75 |
MAX_IMAGE_SIZE = 1024
|
76 |
|
77 |
@spaces.GPU
|
78 |
-
def
|
79 |
image = None,
|
80 |
-
controlnet_type = "Depth",
|
81 |
negative_prompt = "",
|
82 |
seed = 0,
|
83 |
randomize_seed = False,
|
@@ -91,14 +90,8 @@ def infer(prompt,
|
|
91 |
seed = random.randint(0, MAX_SEED)
|
92 |
generator = torch.Generator().manual_seed(seed)
|
93 |
init_image = resize_image(image, MAX_IMAGE_SIZE)
|
94 |
-
|
95 |
-
|
96 |
-
condi_img = process_depth_condition_midas( np.array(init_image), MAX_IMAGE_SIZE)
|
97 |
-
elif controlnet_type == "Canny":
|
98 |
-
pipe = pipe_canny.to("cuda")
|
99 |
-
condi_img = process_canny_condition(np.array(init_image))
|
100 |
-
else:
|
101 |
-
return None
|
102 |
image = pipe(
|
103 |
prompt= prompt ,
|
104 |
image = init_image,
|
@@ -114,8 +107,38 @@ def infer(prompt,
|
|
114 |
).images[0]
|
115 |
return [condi_img, image]
|
116 |
|
117 |
-
|
118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
|
120 |
canny_examples = [
|
121 |
["一个漂亮的女孩,高品质,超清晰,色彩鲜艳,超高分辨率,最佳品质,8k,高清,4K",
|
@@ -228,7 +251,7 @@ with gr.Blocks(css=css) as Kolors:
|
|
228 |
|
229 |
with gr.Row():
|
230 |
gr.Examples(
|
231 |
-
fn =
|
232 |
examples = canny_examples,
|
233 |
inputs = [prompt, image],
|
234 |
outputs = [result],
|
@@ -236,29 +259,22 @@ with gr.Blocks(css=css) as Kolors:
|
|
236 |
)
|
237 |
with gr.Row():
|
238 |
gr.Examples(
|
239 |
-
fn =
|
240 |
examples = depth_examples,
|
241 |
inputs = [prompt, image],
|
242 |
outputs = [result],
|
243 |
label = "Depth"
|
244 |
)
|
245 |
|
|
|
246 |
canny_button.click(
|
247 |
-
fn =
|
248 |
-
inputs = "Canny",
|
249 |
-
outputs = controlnet_type
|
250 |
-
).then(
|
251 |
-
fn = infer,
|
252 |
inputs = [prompt, image, controlnet_type, negative_prompt, seed, randomize_seed, guidance_scale, num_inference_steps, controlnet_conditioning_scale, control_guidance_end, strength],
|
253 |
outputs = [result]
|
254 |
)
|
255 |
|
256 |
depth_button.click(
|
257 |
-
fn =
|
258 |
-
inputs = "Depth",
|
259 |
-
outputs = controlnet_type
|
260 |
-
).then(
|
261 |
-
fn = infer,
|
262 |
inputs = [prompt, image, controlnet_type, negative_prompt, seed, randomize_seed, guidance_scale, num_inference_steps, controlnet_conditioning_scale, control_guidance_end, strength],
|
263 |
outputs = [result]
|
264 |
)
|
|
|
75 |
MAX_IMAGE_SIZE = 1024
|
76 |
|
77 |
@spaces.GPU
|
78 |
+
def infer_depth(prompt,
|
79 |
image = None,
|
|
|
80 |
negative_prompt = "",
|
81 |
seed = 0,
|
82 |
randomize_seed = False,
|
|
|
90 |
seed = random.randint(0, MAX_SEED)
|
91 |
generator = torch.Generator().manual_seed(seed)
|
92 |
init_image = resize_image(image, MAX_IMAGE_SIZE)
|
93 |
+
pipe = pipe_depth.to("cuda")
|
94 |
+
condi_img = process_depth_condition_midas( np.array(init_image), MAX_IMAGE_SIZE)
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
image = pipe(
|
96 |
prompt= prompt ,
|
97 |
image = init_image,
|
|
|
107 |
).images[0]
|
108 |
return [condi_img, image]
|
109 |
|
110 |
+
@spaces.GPU
|
111 |
+
def infer_canny(prompt,
|
112 |
+
image = None,
|
113 |
+
negative_prompt = "",
|
114 |
+
seed = 0,
|
115 |
+
randomize_seed = False,
|
116 |
+
guidance_scale = 6.0,
|
117 |
+
num_inference_steps = 50,
|
118 |
+
controlnet_conditioning_scale = 0.7,
|
119 |
+
control_guidance_end = 0.9,
|
120 |
+
strength = 1.0
|
121 |
+
):
|
122 |
+
if randomize_seed:
|
123 |
+
seed = random.randint(0, MAX_SEED)
|
124 |
+
generator = torch.Generator().manual_seed(seed)
|
125 |
+
init_image = resize_image(image, MAX_IMAGE_SIZE)
|
126 |
+
pipe = pipe_canny.to("cuda")
|
127 |
+
condi_img = process_canny_condition(np.array(init_image))
|
128 |
+
image = pipe(
|
129 |
+
prompt= prompt ,
|
130 |
+
image = init_image,
|
131 |
+
controlnet_conditioning_scale = controlnet_conditioning_scale,
|
132 |
+
control_guidance_end = control_guidance_end,
|
133 |
+
strength= strength ,
|
134 |
+
control_image = condi_img,
|
135 |
+
negative_prompt= negative_prompt ,
|
136 |
+
num_inference_steps= num_inference_steps,
|
137 |
+
guidance_scale= guidance_scale,
|
138 |
+
num_images_per_prompt=1,
|
139 |
+
generator=generator,
|
140 |
+
).images[0]
|
141 |
+
return [condi_img, image]
|
142 |
|
143 |
canny_examples = [
|
144 |
["一个漂亮的女孩,高品质,超清晰,色彩鲜艳,超高分辨率,最佳品质,8k,高清,4K",
|
|
|
251 |
|
252 |
with gr.Row():
|
253 |
gr.Examples(
|
254 |
+
fn = infer_canny,
|
255 |
examples = canny_examples,
|
256 |
inputs = [prompt, image],
|
257 |
outputs = [result],
|
|
|
259 |
)
|
260 |
with gr.Row():
|
261 |
gr.Examples(
|
262 |
+
fn = infer_depth,
|
263 |
examples = depth_examples,
|
264 |
inputs = [prompt, image],
|
265 |
outputs = [result],
|
266 |
label = "Depth"
|
267 |
)
|
268 |
|
269 |
+
|
270 |
canny_button.click(
|
271 |
+
fn = infer_canny,
|
|
|
|
|
|
|
|
|
272 |
inputs = [prompt, image, controlnet_type, negative_prompt, seed, randomize_seed, guidance_scale, num_inference_steps, controlnet_conditioning_scale, control_guidance_end, strength],
|
273 |
outputs = [result]
|
274 |
)
|
275 |
|
276 |
depth_button.click(
|
277 |
+
fn = infer_depth,
|
|
|
|
|
|
|
|
|
278 |
inputs = [prompt, image, controlnet_type, negative_prompt, seed, randomize_seed, guidance_scale, num_inference_steps, controlnet_conditioning_scale, control_guidance_end, strength],
|
279 |
outputs = [result]
|
280 |
)
|