Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -130,7 +130,7 @@ def preprocess_image(image: Image.Image,
|
|
| 130 |
num_steps: int = 25,
|
| 131 |
guidance_scale: float = 5,
|
| 132 |
controlnet_conditioning_scale: float = 1.0,
|
| 133 |
-
|
| 134 |
"""
|
| 135 |
Preprocess the input image.
|
| 136 |
|
|
@@ -141,35 +141,32 @@ def preprocess_image(image: Image.Image,
|
|
| 141 |
Image.Image: The preprocessed image.
|
| 142 |
"""
|
| 143 |
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
| 149 |
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
-
prompt, negative_prompt = apply_style(style_name, prompt, negative_prompt)
|
| 153 |
-
|
| 154 |
-
print("params:", prompt, negative_prompt, style_name, num_steps, guidance_scale, controlnet_conditioning_scale)
|
| 155 |
-
image = pipe_control(
|
| 156 |
-
prompt=prompt,
|
| 157 |
-
negative_prompt=negative_prompt,
|
| 158 |
-
image=image,
|
| 159 |
-
num_inference_steps=num_steps,
|
| 160 |
-
controlnet_conditioning_scale=controlnet_conditioning_scale,
|
| 161 |
-
guidance_scale=guidance_scale,
|
| 162 |
-
width=new_width,
|
| 163 |
-
height=new_height).images[0]
|
| 164 |
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
return processed_image, False
|
| 168 |
-
else:
|
| 169 |
-
return image, False
|
| 170 |
|
| 171 |
|
| 172 |
-
def preprocess_images(images: List[Tuple[Image.Image, str]]
|
| 173 |
"""
|
| 174 |
Preprocess a list of input images.
|
| 175 |
|
|
@@ -394,12 +391,13 @@ with gr.Blocks(delete_cache=(600, 600), js=js_func) as demo:
|
|
| 394 |
with gr.Tab(label="Single Image", id=0) as single_image_input_tab:
|
| 395 |
#image_prompt = gr.Image(label="Image Prompt", format="png", image_mode="RGBA", type="pil", height=300)
|
| 396 |
image_prompt = gr.ImageEditor(type="pil", image_mode="L", crop_size=(512, 512))
|
| 397 |
-
|
| 398 |
-
|
|
|
|
|
|
|
| 399 |
prompt = gr.Textbox(label="Prompt")
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
negative_prompt = gr.Textbox(label="Negative prompt")
|
| 403 |
with gr.Tab(label="Multiple Images", id=1, visible=False) as multiimage_input_tab:
|
| 404 |
multiimage_prompt = gr.Gallery(label="Image Prompt", format="png", type="pil", height=300, columns=3)
|
| 405 |
gr.Markdown("""
|
|
@@ -409,18 +407,43 @@ with gr.Blocks(delete_cache=(600, 600), js=js_func) as demo:
|
|
| 409 |
""")
|
| 410 |
|
| 411 |
with gr.Accordion(label="Generation Settings", open=False):
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 424 |
generate_btn = gr.Button("Generate")
|
| 425 |
|
| 426 |
with gr.Accordion(label="GLB Extraction Settings", open=False):
|
|
@@ -489,13 +512,13 @@ with gr.Blocks(delete_cache=(600, 600), js=js_func) as demo:
|
|
| 489 |
# )
|
| 490 |
sketch_btn.click(
|
| 491 |
preprocess_image,
|
| 492 |
-
inputs=[image_prompt, prompt, negative_prompt, style,
|
| 493 |
-
outputs=[image_prompt
|
| 494 |
)
|
| 495 |
multiimage_prompt.upload(
|
| 496 |
preprocess_images,
|
| 497 |
inputs=[multiimage_prompt],
|
| 498 |
-
outputs=[multiimage_prompt
|
| 499 |
)
|
| 500 |
|
| 501 |
generate_btn.click(
|
|
@@ -504,8 +527,8 @@ with gr.Blocks(delete_cache=(600, 600), js=js_func) as demo:
|
|
| 504 |
outputs=[seed],
|
| 505 |
).then(
|
| 506 |
image_to_3d,
|
| 507 |
-
inputs=[image_prompt, multiimage_prompt, is_multiimage, seed, ss_guidance_strength, ss_sampling_steps, slat_guidance_strength, slat_sampling_steps, multiimage_algo
|
| 508 |
-
outputs=[output_buf, video_output
|
| 509 |
).then(
|
| 510 |
lambda: tuple([gr.Button(interactive=True), gr.Button(interactive=True)]),
|
| 511 |
outputs=[extract_glb_btn, extract_gs_btn],
|
|
|
|
| 130 |
num_steps: int = 25,
|
| 131 |
guidance_scale: float = 5,
|
| 132 |
controlnet_conditioning_scale: float = 1.0,
|
| 133 |
+
) -> Image.Image:
|
| 134 |
"""
|
| 135 |
Preprocess the input image.
|
| 136 |
|
|
|
|
| 141 |
Image.Image: The preprocessed image.
|
| 142 |
"""
|
| 143 |
|
| 144 |
+
width, height = image['composite'].size
|
| 145 |
+
ratio = np.sqrt(1024. * 1024. / (width * height))
|
| 146 |
+
new_width, new_height = int(width * ratio), int(height * ratio)
|
| 147 |
+
image = image['composite'].resize((new_width, new_height))
|
| 148 |
+
|
| 149 |
+
print("image:",type(image))
|
| 150 |
+
|
| 151 |
+
prompt, negative_prompt = apply_style(style_name, prompt, negative_prompt)
|
| 152 |
|
| 153 |
+
print("params:", prompt, negative_prompt, style_name, num_steps, guidance_scale, controlnet_conditioning_scale)
|
| 154 |
+
image = pipe_control(
|
| 155 |
+
prompt=prompt,
|
| 156 |
+
negative_prompt=negative_prompt,
|
| 157 |
+
image=image,
|
| 158 |
+
num_inference_steps=num_steps,
|
| 159 |
+
controlnet_conditioning_scale=controlnet_conditioning_scale,
|
| 160 |
+
guidance_scale=guidance_scale,
|
| 161 |
+
width=new_width,
|
| 162 |
+
height=new_height).images[0]
|
| 163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
+
processed_image = pipeline.preprocess_image(image)
|
| 166 |
+
return processed_image
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
|
| 169 |
+
def preprocess_images(images: List[Tuple[Image.Image, str]]) -> List[Image.Image]:
|
| 170 |
"""
|
| 171 |
Preprocess a list of input images.
|
| 172 |
|
|
|
|
| 391 |
with gr.Tab(label="Single Image", id=0) as single_image_input_tab:
|
| 392 |
#image_prompt = gr.Image(label="Image Prompt", format="png", image_mode="RGBA", type="pil", height=300)
|
| 393 |
image_prompt = gr.ImageEditor(type="pil", image_mode="L", crop_size=(512, 512))
|
| 394 |
+
with gr.Row():
|
| 395 |
+
sketch_btn = gr.Button("process sketch")
|
| 396 |
+
generate_btn = gr.Button("Generate 3D")
|
| 397 |
+
with gr.Row():
|
| 398 |
prompt = gr.Textbox(label="Prompt")
|
| 399 |
+
style = gr.Dropdown(label="Style", choices=STYLE_NAMES, value=DEFAULT_STYLE_NAME)
|
| 400 |
+
|
|
|
|
| 401 |
with gr.Tab(label="Multiple Images", id=1, visible=False) as multiimage_input_tab:
|
| 402 |
multiimage_prompt = gr.Gallery(label="Image Prompt", format="png", type="pil", height=300, columns=3)
|
| 403 |
gr.Markdown("""
|
|
|
|
| 407 |
""")
|
| 408 |
|
| 409 |
with gr.Accordion(label="Generation Settings", open=False):
|
| 410 |
+
with gr.Tab(label="sketch-to-image generation"):
|
| 411 |
+
negative_prompt = gr.Textbox(label="Negative prompt")
|
| 412 |
+
|
| 413 |
+
num_steps = gr.Slider(
|
| 414 |
+
label="Number of steps",
|
| 415 |
+
minimum=1,
|
| 416 |
+
maximum=20,
|
| 417 |
+
step=1,
|
| 418 |
+
value=10,
|
| 419 |
+
)
|
| 420 |
+
guidance_scale = gr.Slider(
|
| 421 |
+
label="Guidance scale",
|
| 422 |
+
minimum=0.1,
|
| 423 |
+
maximum=10.0,
|
| 424 |
+
step=0.1,
|
| 425 |
+
value=5,
|
| 426 |
+
)
|
| 427 |
+
controlnet_conditioning_scale = gr.Slider(
|
| 428 |
+
label="controlnet conditioning scale",
|
| 429 |
+
minimum=0.5,
|
| 430 |
+
maximum=5.0,
|
| 431 |
+
step=0.1,
|
| 432 |
+
value=0.9,
|
| 433 |
+
)
|
| 434 |
+
with gr.Tab(label="3D generation"):
|
| 435 |
+
seed = gr.Slider(0, MAX_SEED, label="Seed", value=0, step=1)
|
| 436 |
+
randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
|
| 437 |
+
gr.Markdown("Stage 1: Sparse Structure Generation")
|
| 438 |
+
with gr.Row():
|
| 439 |
+
ss_guidance_strength = gr.Slider(0.0, 10.0, label="Guidance Strength", value=7.5, step=0.1)
|
| 440 |
+
ss_sampling_steps = gr.Slider(1, 50, label="Sampling Steps", value=12, step=1)
|
| 441 |
+
gr.Markdown("Stage 2: Structured Latent Generation")
|
| 442 |
+
with gr.Row():
|
| 443 |
+
slat_guidance_strength = gr.Slider(0.0, 10.0, label="Guidance Strength", value=3.0, step=0.1)
|
| 444 |
+
slat_sampling_steps = gr.Slider(1, 50, label="Sampling Steps", value=12, step=1)
|
| 445 |
+
multiimage_algo = gr.Radio(["stochastic", "multidiffusion"], label="Multi-image Algorithm", value="stochastic")
|
| 446 |
+
|
| 447 |
generate_btn = gr.Button("Generate")
|
| 448 |
|
| 449 |
with gr.Accordion(label="GLB Extraction Settings", open=False):
|
|
|
|
| 512 |
# )
|
| 513 |
sketch_btn.click(
|
| 514 |
preprocess_image,
|
| 515 |
+
inputs=[image_prompt, prompt, negative_prompt, style, num_steps, guidance_scale, controlnet_conditioning_scale],
|
| 516 |
+
outputs=[image_prompt],
|
| 517 |
)
|
| 518 |
multiimage_prompt.upload(
|
| 519 |
preprocess_images,
|
| 520 |
inputs=[multiimage_prompt],
|
| 521 |
+
outputs=[multiimage_prompt],
|
| 522 |
)
|
| 523 |
|
| 524 |
generate_btn.click(
|
|
|
|
| 527 |
outputs=[seed],
|
| 528 |
).then(
|
| 529 |
image_to_3d,
|
| 530 |
+
inputs=[image_prompt, multiimage_prompt, is_multiimage, seed, ss_guidance_strength, ss_sampling_steps, slat_guidance_strength, slat_sampling_steps, multiimage_algo],
|
| 531 |
+
outputs=[output_buf, video_output],
|
| 532 |
).then(
|
| 533 |
lambda: tuple([gr.Button(interactive=True), gr.Button(interactive=True)]),
|
| 534 |
outputs=[extract_glb_btn, extract_gs_btn],
|