File size: 6,252 Bytes
2c2acce f75e089 95ecf9b f75e089 c99851d 2c2acce 1949e8b 2c2acce 1949e8b c99851d 86ea5fd f8cb6f9 86ea5fd c99851d 86ea5fd a1f69bb 8d4c07e a1f69bb d778d19 a1f69bb 25c2b12 a1f69bb 86ea5fd 3094469 25c2b12 c99851d 657d017 8d4c07e c99851d 8d4c07e 2c2acce 8d4c07e 2c2acce 8d4c07e 95ecf9b 8d4c07e 95ecf9b 8d4c07e 2c2acce 8d4c07e 3aef850 2c2acce 8d4c07e 2c2acce 8d4c07e 2c2acce c99851d 2c2acce 36d6f81 2c2acce 8d4c07e 2c2acce 3aef850 2c2acce 95ecf9b 1949e8b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
import gradio as gr
import os
from util.instantmesh import generate_mvs, make3d, preprocess, check_input_image
from util.text_img import generate_txttoimg, check_prompt, generate_imgtoimg, update_image
_CITE_ = r"""
```bibtex
@article{xu2024instantmesh,
title={InstantMesh: Efficient 3D Mesh Generation from a Single Image with Sparse-view Large Reconstruction Models},
author={Xu, Jiale and Cheng, Weihao and Gao, Yiming and Wang, Xintao and Gao, Shenghua and Shan, Ying},
journal={arXiv preprint arXiv:2404.07191},
year={2024}
}
```
"""
theme = gr.themes.Soft(
primary_hue="orange",
secondary_hue="gray",
neutral_hue="slate",
font=['Montserrat', gr.themes.GoogleFont('ui-sans-serif'), 'system-ui', 'sans-serif'],
)
with gr.Blocks(theme=theme) as GenDemo:
gen_image_var = gr.State()
with gr.Tab("Image to Image Generator"):
with gr.Row(variant="panel"):
with gr.Column():
prompt = gr.Textbox(label="Enter a discription of a shoe")
image = gr.Image(label="Enter an image of a shoe, that you want to use as a reference", type='pil')
strength = gr.Slider(label="Strength", minimum=0.1, maximum=1.0, value=0.5, step=0.1)
gr.Examples(
examples=[
os.path.join("examples", img_name) for img_name in sorted(os.listdir("examples"))
],
inputs=[image],
label="Examples",
cache_examples=False,
)
with gr.Column():
button_img = gr.Button("Generate Image", elem_id="generateIm", variant="primary")
gen_image = gr.Image(label="Generated Image", image_mode="RGBA", type='pil', show_download_button=True, show_label=False)
button_img.click(check_prompt, inputs=[prompt]).success(generate_imgtoimg, inputs=[prompt, image, strength], outputs=[gen_image_var]).success(update_image, inputs=[gen_image_var], outputs=[gen_image])
with gr.Tab("Text to Image Generator"):
with gr.Row(variant="panel"):
with gr.Column():
prompt = gr.Textbox(label="Enter a discription of a shoe")
select = gr.Dropdown(label="Select a model", choices=["Depth","Normal"])
controlNet_image = gr.Image(label="Enter an image of a shoe, that you want to use as a reference", type='pil')
gr.Examples(
examples=[
os.path.join("examples", img_name) for img_name in sorted(os.listdir("examples"))
],
inputs=[controlNet_image],
label="Examples",
cache_examples=False,
)
with gr.Column():
button_txt = gr.Button("Generate Image", elem_id="generateIm", variant="primary")
gen_image = gr.Image(label="Generated Image", image_mode="RGBA", type='pil', show_download_button=True, show_label=False)
button_txt.click(check_prompt, inputs=[prompt]).success(generate_txttoimg, inputs=[prompt, controlNet_image, select], outputs=[gen_image_var]).success(update_image, inputs=[gen_image_var], outputs=[gen_image])
with gr.Tab("Image to 3D Model Generator"):
with gr.Row(variant="panel"):
with gr.Column():
with gr.Row():
input_image = gr.Image(
label="Input Image",
image_mode="RGBA",
type="pil",
interactive=True
)
processed_image = gr.Image(
label="Processed Image",
image_mode="RGBA",
#width=256,
#height=256,
type="pil",
interactive=False
)
with gr.Row():
with gr.Group():
do_remove_background = gr.Checkbox(
label="Remove Background", value=True
)
sample_seed = gr.Number(value=42, label="Seed Value", precision=0)
sample_steps = gr.Slider(
label="Sample Steps",
minimum=30,
maximum=75,
value=75,
step=5
)
with gr.Row():
submit = gr.Button("Generate", elem_id="generate", variant="primary")
with gr.Column():
with gr.Row():
with gr.Column():
mv_show_images = gr.Image(
label="Generated Multi-views",
type="pil",
width=379,
interactive=False
)
with gr.Row():
with gr.Tab("glb"):
output_model_glb = gr.Model3D(
label="Output Model (GLB Format)",
interactive=False,
)
with gr.Tab("obj"):
output_model_obj = gr.Model3D(
label="Output Model (OBJ Format)",
interactive=False,
)
with gr.Row():
gr.Markdown('''Try a different <b>seed value</b> if the result is unsatisfying (Default: 42).''')
gr.Markdown(_CITE_)
mv_images = gr.State()
submit.click(fn=check_input_image, inputs=[gen_image_var]).success(
fn=preprocess,
inputs=[gen_image_var, do_remove_background],
outputs=[processed_image],
).success(
fn=generate_mvs,
inputs=[processed_image, sample_steps, sample_seed],
outputs=[mv_images, mv_show_images]
).success(
fn=make3d,
inputs=[mv_images],
outputs=[output_model_obj, output_model_glb]
)
GenDemo.launch() |