Image-Caption-2-Shap-E / app_text_to_3d.py
fffiloni's picture
Update app_text_to_3d.py
28477f3
#!/usr/bin/env python
import gradio as gr
from model import Model
from settings import CACHE_EXAMPLES, MAX_SEED
from utils import randomize_seed_fn
css="""
#col-container {max-width: 910px; margin-left: auto; margin-right: auto;}
a {text-decoration-line: underline; font-weight: 600;}
"""
def create_demo(model: Model) -> gr.Blocks:
with gr.Blocks(css=css) as demo:
with gr.Box(elem_id="col-container"):
with gr.Row(elem_id='prompt-container'):
image_init = gr.Image(type="filepath", source="upload")
prompt = gr.Text(
label='Prompt',
show_label=False,
max_lines=1,
placeholder='Enter your prompt',
visible=False).style(container=False)
run_button = gr.Button('Run').style(full_width=False)
caption = gr.Textbox(label="Caption from CoCa")
result = gr.Model3D(label='Result', show_label=False)
with gr.Accordion('Advanced options', open=False):
seed = gr.Slider(label='Seed',
minimum=0,
maximum=MAX_SEED,
step=1,
value=0)
randomize_seed = gr.Checkbox(label='Randomize seed',
value=True)
guidance_scale = gr.Slider(label='Guidance scale',
minimum=1,
maximum=20,
step=0.1,
value=15.0)
num_inference_steps = gr.Slider(
label='Number of inference steps',
minimum=1,
maximum=100,
step=1,
value=64)
inputs = [
image_init,
seed,
guidance_scale,
num_inference_steps,
]
run_button.click(
fn=randomize_seed_fn,
inputs=[seed, randomize_seed],
outputs=seed,
queue=False,
).then(
fn=model.run_text,
inputs=inputs,
outputs=[caption, result],
api_name='text-to-3d',
)
return demo