JiantaoLin commited on
Commit
a473409
·
1 Parent(s): 0d6adf0
Files changed (1) hide show
  1. app.py +202 -202
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
- 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](https://img.shields.io/badge/arXiv-Link-red)]({ARXIV_LINK}) [![GitHub](https://img.shields.io/badge/GitHub-Repo-blue)]({GITHUB_LINK})
378
- # """, elem_id="title")
379
- # with gr.Column(scale=1):
380
- # pass
381
- # with gr.Row():
382
- # gr.Markdown(f"[![arXiv](https://img.shields.io/badge/arXiv-Link-red)]({ARXIV_LINK})")
383
- # gr.Markdown(f"[![GitHub](https://img.shields.io/badge/GitHub-Repo-blue)]({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()
 
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](https://img.shields.io/badge/arXiv-Link-red)]({ARXIV_LINK}) [![GitHub](https://img.shields.io/badge/GitHub-Repo-blue)]({GITHUB_LINK})
378
+ # """, elem_id="title")
379
+ # with gr.Column(scale=1):
380
+ # pass
381
+ # with gr.Row():
382
+ # gr.Markdown(f"[![arXiv](https://img.shields.io/badge/arXiv-Link-red)]({ARXIV_LINK})")
383
+ # gr.Markdown(f"[![GitHub](https://img.shields.io/badge/GitHub-Repo-blue)]({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()