Spaces:
Running
on
L40S
Running
on
L40S
Upload app_hg.py with huggingface_hub
Browse files
app_hg.py
CHANGED
@@ -136,7 +136,7 @@ CONST_HEADER = '''
|
|
136 |
CONST_NOTE = '''
|
137 |
❗️❗️❗️Usage❗️❗️❗️<br>
|
138 |
|
139 |
-
Limited by format, the model can only export *.obj mesh with vertex colors. The "
|
140 |
Please click "Do Rendering" to export a GIF.<br>
|
141 |
You can click "Do Baking" to bake multi-view imgaes onto the shape.<br>
|
142 |
|
@@ -247,9 +247,9 @@ def stage_3_v23(
|
|
247 |
seed,
|
248 |
save_folder,
|
249 |
target_face_count = 30000,
|
250 |
-
texture_color = '
|
251 |
):
|
252 |
-
do_texture_mapping = texture_color == '
|
253 |
worker_v23(
|
254 |
views_pil,
|
255 |
cond_pil,
|
@@ -265,7 +265,7 @@ def stage_3_v23(
|
|
265 |
|
266 |
@spaces.GPU
|
267 |
def stage_3p_baking(save_folder, color, bake, force, front, others, align_times):
|
268 |
-
if color == "
|
269 |
obj_dst = worker_baker(save_folder, force, front, others, align_times)
|
270 |
glb_dst = obj_dst.replace(".obj", ".glb")
|
271 |
return glb_dst
|
@@ -307,24 +307,24 @@ def check_image_available(image):
|
|
307 |
|
308 |
def update_mode(mode):
|
309 |
color_change = {
|
310 |
-
'
|
311 |
-
'
|
312 |
-
'
|
313 |
}[mode]
|
314 |
bake_change = {
|
315 |
-
'
|
316 |
-
'
|
317 |
-
'
|
318 |
}[mode]
|
319 |
face_change = {
|
320 |
-
'
|
321 |
'Moderate': gr.update(value=60000, maximum=300000),
|
322 |
-
'
|
323 |
}[mode]
|
324 |
render_change = {
|
325 |
-
'
|
326 |
-
'
|
327 |
-
'
|
328 |
}[mode]
|
329 |
return color_change, bake_change, face_change, render_change
|
330 |
|
@@ -345,17 +345,17 @@ with gr.Blocks() as demo:
|
|
345 |
with gr.Tab("Text to 3D"):
|
346 |
with gr.Column():
|
347 |
text = gr.TextArea('一只黑白相间的熊猫在白色背景上居中坐着,呈现出卡通风格和可爱氛围。',
|
348 |
-
lines=3, max_lines=20, label='Input text')
|
349 |
|
350 |
textgen_mode = gr.Radio(
|
351 |
-
choices=['
|
352 |
-
label="
|
353 |
-
value='
|
354 |
interactive=True
|
355 |
)
|
356 |
|
357 |
with gr.Accordion("Custom settings", open=False):
|
358 |
-
textgen_color = gr.Radio(choices=["vertex", "
|
359 |
|
360 |
with gr.Row():
|
361 |
textgen_render = gr.Checkbox(
|
@@ -413,12 +413,12 @@ with gr.Blocks() as demo:
|
|
413 |
)
|
414 |
textgen_other_views = gr.CheckboxGroup(
|
415 |
choices=['60°', '120°', '180°', '240°', '300°'],
|
416 |
-
label="Other views
|
417 |
value=['180°'],
|
418 |
interactive=True,
|
419 |
visible=True
|
420 |
)
|
421 |
-
textgen_align_times =gr.Slider(
|
422 |
value=3,
|
423 |
minimum=1,
|
424 |
maximum=5,
|
@@ -441,19 +441,33 @@ with gr.Blocks() as demo:
|
|
441 |
)
|
442 |
textgen_color.change(
|
443 |
fn=lambda x:[
|
444 |
-
gr.update(value=(x=='
|
445 |
-
gr.update(value=(x=='
|
446 |
],
|
447 |
inputs=textgen_color,
|
448 |
-
outputs=[
|
|
|
|
|
|
|
449 |
)
|
450 |
textgen_bake.change(
|
451 |
-
fn= lambda x:[
|
|
|
|
|
|
|
|
|
|
|
|
|
452 |
inputs=textgen_bake,
|
453 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
454 |
)
|
455 |
|
456 |
-
|
457 |
### Image iutput region
|
458 |
|
459 |
with gr.Tab("Image to 3D"):
|
@@ -464,14 +478,14 @@ with gr.Blocks() as demo:
|
|
464 |
alert_message = gr.Markdown("") # for warning
|
465 |
|
466 |
imggen_mode = gr.Radio(
|
467 |
-
choices=['
|
468 |
-
label="
|
469 |
-
value='
|
470 |
interactive=True
|
471 |
)
|
472 |
|
473 |
with gr.Accordion("Custom settings", open=False):
|
474 |
-
imggen_color = gr.Radio(choices=["vertex", "
|
475 |
|
476 |
with gr.Row():
|
477 |
imggen_removebg = gr.Checkbox(
|
@@ -499,7 +513,7 @@ with gr.Blocks() as demo:
|
|
499 |
label="Gen steps",
|
500 |
interactive=True
|
501 |
)
|
502 |
-
imggen_max_faces =gr.Slider(
|
503 |
value=10000,
|
504 |
minimum=2000,
|
505 |
maximum=60000,
|
@@ -523,7 +537,7 @@ with gr.Blocks() as demo:
|
|
523 |
)
|
524 |
imggen_other_views = gr.CheckboxGroup(
|
525 |
choices=['60°', '120°', '180°', '240°', '300°'],
|
526 |
-
label="Other views
|
527 |
value=['180°'],
|
528 |
interactive=True,
|
529 |
visible=True
|
@@ -550,15 +564,33 @@ with gr.Blocks() as demo:
|
|
550 |
)
|
551 |
|
552 |
imggen_color.change(
|
553 |
-
fn=lambda x:[
|
|
|
|
|
|
|
554 |
inputs=imggen_color,
|
555 |
-
outputs=[
|
|
|
|
|
|
|
556 |
)
|
557 |
|
558 |
imggen_bake.change(
|
559 |
-
fn= lambda x:[
|
|
|
|
|
|
|
|
|
|
|
|
|
560 |
inputs=imggen_bake,
|
561 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
562 |
)
|
563 |
|
564 |
with gr.Row():
|
@@ -567,7 +599,6 @@ with gr.Blocks() as demo:
|
|
567 |
with gr.Row():
|
568 |
gr.Examples(examples=example_is, inputs=[input_image],
|
569 |
label="Img examples", examples_per_page=10)
|
570 |
-
|
571 |
|
572 |
gr.Markdown(CONST_NOTE)
|
573 |
|
@@ -600,7 +631,7 @@ with gr.Blocks() as demo:
|
|
600 |
|
601 |
result_3dglb_texture = gr.Model3D(
|
602 |
clear_color=[0.0, 0.0, 0.0, 0.0],
|
603 |
-
label="GLB
|
604 |
show_label=True,
|
605 |
visible=True,
|
606 |
camera_position=[90, 90, None],
|
@@ -608,7 +639,7 @@ with gr.Blocks() as demo:
|
|
608 |
|
609 |
result_3dglb_baked = gr.Model3D(
|
610 |
clear_color=[0.0, 0.0, 0.0, 0.0],
|
611 |
-
label="GLB
|
612 |
show_label=True,
|
613 |
visible=True,
|
614 |
camera_position=[90, 90, None],
|
@@ -619,7 +650,7 @@ with gr.Blocks() as demo:
|
|
619 |
with gr.Row():
|
620 |
gr.Markdown(
|
621 |
"Due to Gradio limitations, OBJ files are displayed with vertex shading only, "
|
622 |
-
"while GLB files can be viewed with
|
623 |
"we recommend downloading the GLB files and opening them with 3D software "
|
624 |
"like Blender or MeshLab."
|
625 |
)
|
@@ -662,7 +693,7 @@ with gr.Blocks() as demo:
|
|
662 |
fn=stage_4_gif,
|
663 |
inputs=[save_folder, textgen_color, textgen_bake, textgen_render],
|
664 |
outputs=[result_gif],
|
665 |
-
).success(lambda: print('Text_to_3D Done
|
666 |
|
667 |
|
668 |
imggen_submit.click(
|
@@ -690,7 +721,7 @@ with gr.Blocks() as demo:
|
|
690 |
fn=stage_4_gif,
|
691 |
inputs=[save_folder, imggen_color, imggen_bake, imggen_render],
|
692 |
outputs=[result_gif],
|
693 |
-
).success(lambda: print('Image_to_3D Done
|
694 |
|
695 |
#===============================================================
|
696 |
# start gradio server
|
|
|
136 |
CONST_NOTE = '''
|
137 |
❗️❗️❗️Usage❗️❗️❗️<br>
|
138 |
|
139 |
+
Limited by format, the model can only export *.obj mesh with vertex colors. The "face" mod can only work on *.glb.<br>
|
140 |
Please click "Do Rendering" to export a GIF.<br>
|
141 |
You can click "Do Baking" to bake multi-view imgaes onto the shape.<br>
|
142 |
|
|
|
247 |
seed,
|
248 |
save_folder,
|
249 |
target_face_count = 30000,
|
250 |
+
texture_color = 'face'
|
251 |
):
|
252 |
+
do_texture_mapping = texture_color == 'face'
|
253 |
worker_v23(
|
254 |
views_pil,
|
255 |
cond_pil,
|
|
|
265 |
|
266 |
@spaces.GPU
|
267 |
def stage_3p_baking(save_folder, color, bake, force, front, others, align_times):
|
268 |
+
if color == "face" and bake:
|
269 |
obj_dst = worker_baker(save_folder, force, front, others, align_times)
|
270 |
glb_dst = obj_dst.replace(".obj", ".glb")
|
271 |
return glb_dst
|
|
|
307 |
|
308 |
def update_mode(mode):
|
309 |
color_change = {
|
310 |
+
'Vertex color': gr.update(value='vertex'),
|
311 |
+
'Face color': gr.update(value='face'),
|
312 |
+
'Baking': gr.update(value='face')
|
313 |
}[mode]
|
314 |
bake_change = {
|
315 |
+
'Vertex color': gr.update(value=False, interactive=False, visible=False),
|
316 |
+
'Face color': gr.update(value=False),
|
317 |
+
'Baking': gr.update(value=BAKE_AVAILEBLE)
|
318 |
}[mode]
|
319 |
face_change = {
|
320 |
+
'Vertex color': gr.update(value=120000, maximum=300000),
|
321 |
'Moderate': gr.update(value=60000, maximum=300000),
|
322 |
+
'Baking': gr.update(value=10000, maximum=60000)
|
323 |
}[mode]
|
324 |
render_change = {
|
325 |
+
'Vertex color': gr.update(value=False, interactive=False, visible=False),
|
326 |
+
'Face color': gr.update(value=True),
|
327 |
+
'Baking': gr.update(value=True)
|
328 |
}[mode]
|
329 |
return color_change, bake_change, face_change, render_change
|
330 |
|
|
|
345 |
with gr.Tab("Text to 3D"):
|
346 |
with gr.Column():
|
347 |
text = gr.TextArea('一只黑白相间的熊猫在白色背景上居中坐着,呈现出卡通风格和可爱氛围。',
|
348 |
+
lines=3, max_lines=20, label='Input text (within 70 words)')
|
349 |
|
350 |
textgen_mode = gr.Radio(
|
351 |
+
choices=['Vertex color', 'Face color', 'Baking'],
|
352 |
+
label="Texture mode",
|
353 |
+
value='Baking',
|
354 |
interactive=True
|
355 |
)
|
356 |
|
357 |
with gr.Accordion("Custom settings", open=False):
|
358 |
+
textgen_color = gr.Radio(choices=["vertex", "face"], label="Color", value="face")
|
359 |
|
360 |
with gr.Row():
|
361 |
textgen_render = gr.Checkbox(
|
|
|
413 |
)
|
414 |
textgen_other_views = gr.CheckboxGroup(
|
415 |
choices=['60°', '120°', '180°', '240°', '300°'],
|
416 |
+
label="Other views baking",
|
417 |
value=['180°'],
|
418 |
interactive=True,
|
419 |
visible=True
|
420 |
)
|
421 |
+
textgen_align_times = gr.Slider(
|
422 |
value=3,
|
423 |
minimum=1,
|
424 |
maximum=5,
|
|
|
441 |
)
|
442 |
textgen_color.change(
|
443 |
fn=lambda x:[
|
444 |
+
gr.update(value=(x=='face'), interactive=(x=='face'), visible=(x=='face')),
|
445 |
+
gr.update(value=(x=='face'), interactive=(x=='face'), visible=(x=='face')),
|
446 |
],
|
447 |
inputs=textgen_color,
|
448 |
+
outputs=[
|
449 |
+
textgen_bake,
|
450 |
+
textgen_render
|
451 |
+
]
|
452 |
)
|
453 |
textgen_bake.change(
|
454 |
+
fn= lambda x:[
|
455 |
+
gr.update(visible=x),
|
456 |
+
gr.update(visible=x),
|
457 |
+
gr.update(visible=x),
|
458 |
+
gr.update(visible=x),
|
459 |
+
gr.update(value=10000 if x else 120000, minimum=2000, maximum=60000 if x else 300000)
|
460 |
+
],
|
461 |
inputs=textgen_bake,
|
462 |
+
outputs=[
|
463 |
+
textgen_front_baking,
|
464 |
+
textgen_other_views,
|
465 |
+
textgen_align_times,
|
466 |
+
textgen_force_bake,
|
467 |
+
textgen_max_faces
|
468 |
+
]
|
469 |
)
|
470 |
|
|
|
471 |
### Image iutput region
|
472 |
|
473 |
with gr.Tab("Image to 3D"):
|
|
|
478 |
alert_message = gr.Markdown("") # for warning
|
479 |
|
480 |
imggen_mode = gr.Radio(
|
481 |
+
choices=['Vertex color', 'Face color', 'Baking'],
|
482 |
+
label="Texture mode",
|
483 |
+
value='Baking',
|
484 |
interactive=True
|
485 |
)
|
486 |
|
487 |
with gr.Accordion("Custom settings", open=False):
|
488 |
+
imggen_color = gr.Radio(choices=["vertex", "face"], label="Color", value="face")
|
489 |
|
490 |
with gr.Row():
|
491 |
imggen_removebg = gr.Checkbox(
|
|
|
513 |
label="Gen steps",
|
514 |
interactive=True
|
515 |
)
|
516 |
+
imggen_max_faces = gr.Slider(
|
517 |
value=10000,
|
518 |
minimum=2000,
|
519 |
maximum=60000,
|
|
|
537 |
)
|
538 |
imggen_other_views = gr.CheckboxGroup(
|
539 |
choices=['60°', '120°', '180°', '240°', '300°'],
|
540 |
+
label="Other views baking",
|
541 |
value=['180°'],
|
542 |
interactive=True,
|
543 |
visible=True
|
|
|
564 |
)
|
565 |
|
566 |
imggen_color.change(
|
567 |
+
fn=lambda x:[
|
568 |
+
gr.update(value=(x=='face'), interactive=(x=='face'), visible=(x=='face')),
|
569 |
+
gr.update(value=(x=='face'), interactive=(x=='face'), visible=(x=='face'))
|
570 |
+
],
|
571 |
inputs=imggen_color,
|
572 |
+
outputs=[
|
573 |
+
imggen_bake,
|
574 |
+
imggen_render
|
575 |
+
]
|
576 |
)
|
577 |
|
578 |
imggen_bake.change(
|
579 |
+
fn= lambda x:[
|
580 |
+
gr.update(visible=x),
|
581 |
+
gr.update(visible=x),
|
582 |
+
gr.update(visible=x),
|
583 |
+
gr.update(visible=x),
|
584 |
+
gr.update( value=10000 if x else 120000, minimum=2000, maximum=60000 if x else 300000)
|
585 |
+
],
|
586 |
inputs=imggen_bake,
|
587 |
+
outputs=[
|
588 |
+
imggen_front_baking,
|
589 |
+
imggen_other_views,
|
590 |
+
imggen_align_times,
|
591 |
+
imggen_force_bake,
|
592 |
+
imggen_max_faces
|
593 |
+
]
|
594 |
)
|
595 |
|
596 |
with gr.Row():
|
|
|
599 |
with gr.Row():
|
600 |
gr.Examples(examples=example_is, inputs=[input_image],
|
601 |
label="Img examples", examples_per_page=10)
|
|
|
602 |
|
603 |
gr.Markdown(CONST_NOTE)
|
604 |
|
|
|
631 |
|
632 |
result_3dglb_texture = gr.Model3D(
|
633 |
clear_color=[0.0, 0.0, 0.0, 0.0],
|
634 |
+
label="GLB face color",
|
635 |
show_label=True,
|
636 |
visible=True,
|
637 |
camera_position=[90, 90, None],
|
|
|
639 |
|
640 |
result_3dglb_baked = gr.Model3D(
|
641 |
clear_color=[0.0, 0.0, 0.0, 0.0],
|
642 |
+
label="GLB baking",
|
643 |
show_label=True,
|
644 |
visible=True,
|
645 |
camera_position=[90, 90, None],
|
|
|
650 |
with gr.Row():
|
651 |
gr.Markdown(
|
652 |
"Due to Gradio limitations, OBJ files are displayed with vertex shading only, "
|
653 |
+
"while GLB files can be viewed with face color. <br>For the best experience, "
|
654 |
"we recommend downloading the GLB files and opening them with 3D software "
|
655 |
"like Blender or MeshLab."
|
656 |
)
|
|
|
693 |
fn=stage_4_gif,
|
694 |
inputs=[save_folder, textgen_color, textgen_bake, textgen_render],
|
695 |
outputs=[result_gif],
|
696 |
+
).success(lambda: print('Text_to_3D Done ...\n'))
|
697 |
|
698 |
|
699 |
imggen_submit.click(
|
|
|
721 |
fn=stage_4_gif,
|
722 |
inputs=[save_folder, imggen_color, imggen_bake, imggen_render],
|
723 |
outputs=[result_gif],
|
724 |
+
).success(lambda: print('Image_to_3D Done ...\n'))
|
725 |
|
726 |
#===============================================================
|
727 |
# start gradio server
|