JiantaoLin
commited on
Commit
Β·
a473409
1
Parent(s):
0d6adf0
new
Browse files
app.py
CHANGED
|
@@ -281,206 +281,206 @@ def image_to_base64(image_path):
|
|
| 281 |
with open(image_path, "rb") as img_file:
|
| 282 |
return base64.b64encode(img_file.read()).decode('utf-8')
|
| 283 |
|
| 284 |
-
def main():
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
|
| 485 |
-
if __name__ == "__main__":
|
| 486 |
-
|
|
|
|
| 281 |
with open(image_path, "rb") as img_file:
|
| 282 |
return base64.b64encode(img_file.read()).decode('utf-8')
|
| 283 |
|
| 284 |
+
# def main():
|
| 285 |
+
|
| 286 |
+
torch.set_grad_enabled(False)
|
| 287 |
+
|
| 288 |
+
# Convert the logo image to base64
|
| 289 |
+
logo_base64 = image_to_base64(LOGO_PATH)
|
| 290 |
+
# with gr.Blocks() as demo:
|
| 291 |
+
with gr.Blocks(css="""
|
| 292 |
+
body {
|
| 293 |
+
display: flex;
|
| 294 |
+
justify-content: center;
|
| 295 |
+
align-items: center;
|
| 296 |
+
min-height: 100vh;
|
| 297 |
+
margin: 0;
|
| 298 |
+
padding: 0;
|
| 299 |
+
}
|
| 300 |
+
#col-container { margin: 0px auto; max-width: 200px; }
|
| 301 |
+
|
| 302 |
+
|
| 303 |
+
.gradio-container {
|
| 304 |
+
max-width: 1000px;
|
| 305 |
+
margin: auto;
|
| 306 |
+
width: 100%;
|
| 307 |
+
}
|
| 308 |
+
#center-align-column {
|
| 309 |
+
display: flex;
|
| 310 |
+
justify-content: center;
|
| 311 |
+
align-items: center;
|
| 312 |
+
}
|
| 313 |
+
#right-align-column {
|
| 314 |
+
display: flex;
|
| 315 |
+
justify-content: flex-end;
|
| 316 |
+
align-items: center;
|
| 317 |
+
}
|
| 318 |
+
h1 {text-align: center;}
|
| 319 |
+
h2 {text-align: center;}
|
| 320 |
+
h3 {text-align: center;}
|
| 321 |
+
p {text-align: center;}
|
| 322 |
+
img {text-align: right;}
|
| 323 |
+
.right {
|
| 324 |
+
display: block;
|
| 325 |
+
margin-left: auto;
|
| 326 |
+
}
|
| 327 |
+
.center {
|
| 328 |
+
display: block;
|
| 329 |
+
margin-left: auto;
|
| 330 |
+
margin-right: auto;
|
| 331 |
+
width: 50%;
|
| 332 |
+
|
| 333 |
+
#content-container {
|
| 334 |
+
max-width: 1200px;
|
| 335 |
+
margin: 0 auto;
|
| 336 |
+
}
|
| 337 |
+
#example-container {
|
| 338 |
+
max-width: 300px;
|
| 339 |
+
margin: 0 auto;
|
| 340 |
+
}
|
| 341 |
+
""",elem_id="col-container") as demo:
|
| 342 |
+
# Header Section
|
| 343 |
+
# gr.Image(value=LOGO_PATH, width=64, height=64)
|
| 344 |
+
# gr.Markdown(_HEADER_)
|
| 345 |
+
with gr.Row(elem_id="content-container"):
|
| 346 |
+
# with gr.Column(scale=1):
|
| 347 |
+
# pass
|
| 348 |
+
# with gr.Column(scale=1, elem_id="right-align-column"):
|
| 349 |
+
# # gr.Image(value=LOGO_PATH, interactive=False, show_label=False, width=64, height=64, elem_id="logo-image")
|
| 350 |
+
# # gr.Markdown(f"<img src='{LOGO_PATH}' alt='Logo' style='width:64px;height:64px;border:0;'>")
|
| 351 |
+
# # gr.HTML(f"<img src='data:image/png;base64,{logo_base64}' alt='Logo' class='right' style='width:64px;height:64px;border:0;text-align:right;'>")
|
| 352 |
+
# pass
|
| 353 |
+
with gr.Column(scale=7, elem_id="center-align-column"):
|
| 354 |
+
gr.Markdown(f"""
|
| 355 |
+
## Official π€ Gradio Demo
|
| 356 |
+
# Kiss3DGen: Repurposing Image Diffusion Models for 3D Asset Generation""")
|
| 357 |
+
gr.HTML(f"<img src='data:image/png;base64,{logo_base64}' alt='Logo' class='center' style='width:64px;height:64px;border:0;text-align:center;'>")
|
| 358 |
+
|
| 359 |
+
gr.HTML(f"""
|
| 360 |
+
<div style="display: flex; justify-content: center; align-items: center; gap: 10px;">
|
| 361 |
+
<a href="{ARXIV_LINK}" target="_blank">
|
| 362 |
+
<img src="https://img.shields.io/badge/arXiv-Link-red" alt="arXiv">
|
| 363 |
+
</a>
|
| 364 |
+
<a href="{GITHUB_LINK}" target="_blank">
|
| 365 |
+
<img src="https://img.shields.io/badge/GitHub-Repo-blue" alt="GitHub">
|
| 366 |
+
</a>
|
| 367 |
+
</div>
|
| 368 |
+
|
| 369 |
+
""")
|
| 370 |
+
|
| 371 |
+
|
| 372 |
+
# gr.HTML(f"""
|
| 373 |
+
# <div style="display: flex; gap: 10px; align-items: center;"><a href="{ARXIV_LINK}" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/arXiv-Link-red" alt="arXiv"></a> <a href="{GITHUB_LINK}" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/GitHub-Repo-blue" alt="GitHub"></a></div>
|
| 374 |
+
# """)
|
| 375 |
+
|
| 376 |
+
# gr.Markdown(f"""
|
| 377 |
+
# []({ARXIV_LINK}) []({GITHUB_LINK})
|
| 378 |
+
# """, elem_id="title")
|
| 379 |
+
# with gr.Column(scale=1):
|
| 380 |
+
# pass
|
| 381 |
+
# with gr.Row():
|
| 382 |
+
# gr.Markdown(f"[]({ARXIV_LINK})")
|
| 383 |
+
# gr.Markdown(f"[]({GITHUB_LINK})")
|
| 384 |
+
|
| 385 |
+
# Tabs Section
|
| 386 |
+
with gr.Tabs(selected='tab_text_to_3d', elem_id="content-container") as main_tabs:
|
| 387 |
+
with gr.TabItem('Text-to-3D', id='tab_text_to_3d'):
|
| 388 |
+
with gr.Row():
|
| 389 |
+
with gr.Column(scale=1):
|
| 390 |
+
prompt = gr.Textbox(value="", label="Input Prompt", lines=4)
|
| 391 |
+
seed1 = gr.Number(value=10, label="Seed")
|
| 392 |
+
|
| 393 |
+
with gr.Row(elem_id="example-container"):
|
| 394 |
+
gr.Examples(
|
| 395 |
+
examples=[
|
| 396 |
+
# ["A tree with red leaves"],
|
| 397 |
+
# ["A dragon with black texture"],
|
| 398 |
+
["A girl with pink hair"],
|
| 399 |
+
["A boy playing guitar"],
|
| 400 |
+
|
| 401 |
+
|
| 402 |
+
["A dog wearing a hat"],
|
| 403 |
+
["A boy playing basketball"],
|
| 404 |
+
# [""],
|
| 405 |
+
# [""],
|
| 406 |
+
# [""],
|
| 407 |
+
|
| 408 |
+
],
|
| 409 |
+
inputs=[prompt], # ε°ιδΈηη€ΊδΎε‘«ε
₯ prompt ζζ¬ζ‘
|
| 410 |
+
label="Example Prompts"
|
| 411 |
+
)
|
| 412 |
+
btn_text2detailed = gr.Button("Refine to detailed prompt")
|
| 413 |
+
detailed_prompt = gr.Textbox(value="", label="Detailed Prompt", placeholder="detailed prompt will be generated here base on your input prompt. You can also edit this prompt", lines=4, interactive=True)
|
| 414 |
+
btn_text2img = gr.Button("Generate Images")
|
| 415 |
+
|
| 416 |
+
with gr.Column(scale=1):
|
| 417 |
+
output_image1 = gr.Image(label="Generated image", interactive=False)
|
| 418 |
+
|
| 419 |
+
|
| 420 |
+
# lrm_radius = gr.Number(value=4.15, label="lrm_radius")
|
| 421 |
+
# isomer_radius = gr.Number(value=4.5, label="isomer_radius")
|
| 422 |
+
# reconstruction_stage1_steps = gr.Number(value=10, label="reconstruction_stage1_steps")
|
| 423 |
+
# reconstruction_stage2_steps = gr.Number(value=50, label="reconstruction_stage2_steps")
|
| 424 |
+
|
| 425 |
+
btn_gen_mesh = gr.Button("Generate Mesh")
|
| 426 |
+
output_video1 = gr.Video(label="Generated Video", interactive=False, loop=True, autoplay=True)
|
| 427 |
+
btn_download1 = gr.Button("Download Mesh")
|
| 428 |
+
|
| 429 |
+
file_output1 = gr.File()
|
| 430 |
+
|
| 431 |
+
with gr.TabItem('Image-to-3D', id='tab_image_to_3d'):
|
| 432 |
+
with gr.Row():
|
| 433 |
+
with gr.Column(scale=1):
|
| 434 |
+
image = gr.Image(label="Input Image", type="pil")
|
| 435 |
+
|
| 436 |
+
seed2 = gr.Number(value=10, label="Seed (0 for random)")
|
| 437 |
+
|
| 438 |
+
btn_img2mesh_preprocess = gr.Button("Preprocess Image")
|
| 439 |
+
|
| 440 |
+
image_caption = gr.Textbox(value="", label="Image Caption", placeholder="caption will be generated here base on your input image. You can also edit this caption", lines=4, interactive=True)
|
| 441 |
+
|
| 442 |
+
output_image2 = gr.Image(label="Generated image", interactive=False)
|
| 443 |
+
strength1 = gr.Slider(minimum=0, maximum=1.0, step=0.01, value=0.5, label="strength1")
|
| 444 |
+
strength2 = gr.Slider(minimum=0, maximum=1.0, step=0.01, value=0.95, label="strength2")
|
| 445 |
+
enable_redux = gr.Checkbox(label="enable redux", value=True)
|
| 446 |
+
use_controlnet = gr.Checkbox(label="use controlnet", value=True)
|
| 447 |
+
|
| 448 |
+
btn_img2mesh_main = gr.Button("Generate Mesh")
|
| 449 |
+
|
| 450 |
+
with gr.Column(scale=1):
|
| 451 |
+
|
| 452 |
+
# output_mesh2 = gr.Model3D(label="Generated Mesh", interactive=False)
|
| 453 |
+
output_image3 = gr.Image(label="gen save image", interactive=False)
|
| 454 |
+
output_video2 = gr.Video(label="Generated Video", interactive=False, loop=True, autoplay=True)
|
| 455 |
+
btn_download2 = gr.Button("Download Mesh")
|
| 456 |
+
file_output2 = gr.File()
|
| 457 |
+
|
| 458 |
+
# Image2
|
| 459 |
+
btn_img2mesh_preprocess.click(fn=image2mesh_preprocess_, inputs=[image, seed2], outputs=[output_image2, image_caption])
|
| 460 |
+
|
| 461 |
+
btn_img2mesh_main.click(fn=image2mesh_main_, inputs=[output_image2, image_caption, seed2, strength1, strength2, enable_redux, use_controlnet], outputs=[output_image3, output_video2])
|
| 462 |
+
|
| 463 |
+
|
| 464 |
+
btn_download2.click(fn=save_cached_mesh, inputs=[], outputs=file_output2)
|
| 465 |
+
|
| 466 |
+
|
| 467 |
+
# Button Click Events
|
| 468 |
+
# Text2
|
| 469 |
+
btn_text2detailed.click(fn=text_to_detailed, inputs=[prompt, seed1], outputs=detailed_prompt)
|
| 470 |
+
btn_text2img.click(fn=text_to_image, inputs=[detailed_prompt, seed1], outputs=output_image1)
|
| 471 |
+
btn_gen_mesh.click(fn=bundle_image_to_mesh, inputs=[output_image1,], outputs=output_video1)
|
| 472 |
+
# btn_gen_mesh.click(fn=bundle_image_to_mesh, inputs=[output_image1, lrm_radius, isomer_radius, reconstruction_stage1_steps, reconstruction_stage2_steps], outputs=output_video1)
|
| 473 |
+
|
| 474 |
+
with gr.Row():
|
| 475 |
+
pass
|
| 476 |
+
with gr.Row():
|
| 477 |
+
gr.Markdown(_CITE_)
|
| 478 |
+
|
| 479 |
+
# demo.queue(default_concurrency_limit=1)
|
| 480 |
+
# demo.launch(server_name="0.0.0.0", server_port=9239)
|
| 481 |
+
# subprocess.run("rm -rf /data-nvme/zerogpu-offload/*", env={}, shell=True)
|
| 482 |
+
demo.launch()
|
| 483 |
+
|
| 484 |
|
| 485 |
+
# if __name__ == "__main__":
|
| 486 |
+
# main()
|