Spaces:
Paused
Paused
import logging | |
import os | |
import tempfile | |
import time | |
import gradio as gr | |
import numpy as np | |
import rembg | |
import torch | |
from PIL import Image | |
from functools import partial | |
from tsr.system import TSR | |
from tsr.utils import remove_background, resize_foreground, to_gradio_3d_orientation | |
#... | |
css = """ | |
/*... */ | |
""" | |
with gr.Blocks(theme=CustomTheme(), css=css) as demo: | |
#... | |
with gr.Column(): | |
gr.Markdown("**Input Image**") | |
input_image = gr.Image( | |
label="", | |
image_mode="RGBA", | |
sources="upload", | |
type="pil", | |
elem_id="content_image", | |
width=500, # Увеличена ширина входных изображений | |
) | |
with gr.Column(): | |
do_remove_background = gr.Checkbox( | |
label="Remove Background", | |
value=True, | |
elem_id="remove_background", | |
) | |
foreground_ratio = gr.Slider( | |
label="Foreground Ratio", | |
minimum=0.5, | |
maximum=1.0, | |
value=0.85, | |
step=0.05, | |
elem_id="foreground_ratio", | |
) | |
with gr.Row(): | |
submit = gr.Button( | |
label="Generate", | |
scale=0, | |
variant="primary", | |
elem_classes="generate-button", | |
) | |
output_model = gr.Model3D( | |
label="Output Model", | |
interactive=False, | |
) | |
output_model2 = gr.Model3D( | |
label="Output Model", | |
interactive=False, | |
) | |
with gr.Tab("obj"): | |
output_model = gr.Model3D( | |
label="Output Model", | |
interactive=False, | |
) | |
with gr.Tab("glb"): | |
output_model2 = gr.Model3D( | |
label="Output Model", | |
interactive=False, | |
) | |
#... | |
with gr.Row(): | |
output_model = gr.Model3D( | |
label="Output Model", | |
interactive=False, | |
) | |
output_model2 = gr.Model3D( | |
label="Output Model", | |
interactive=False, | |
) | |
with gr.Column(): | |
gr.Markdown("**Input Image**") | |
input_image = gr.Image( | |
label="", | |
image_mode="RGBA", | |
sources="upload", | |
type="pil", | |
elem_id="content_image", | |
width=500, # Увеличена ширина входных изображений | |
) | |
with gr.Column(): | |
do_remove_background = gr.Checkbox( | |
label="Remove Background", | |
value=True, | |
elem_id="remove_background", | |
) | |
foreground_ratio = gr.Slider( | |
label="Foreground Ratio", | |
minimum=0.5, | |
maximum=1.0, | |
value=0.85, | |
step=0.05, | |
elem_id="foreground_ratio", | |
) | |
with gr.Row(): | |
submit = gr.Button( | |
label="Generate", | |
scale=0, | |
variant="primary", | |
elem_classes="generate-button", | |
) | |
output_model = gr.Model3D( | |
label="Output Model", | |
interactive=False, | |
) | |
output_model2 = gr.Model3D( | |
label="Output Model", | |
interactive=False, | |
) | |
with gr.Tab("obj"): | |
output_model = gr.Model3D( | |
label="Output Model", | |
interactive=False, | |
) | |
output_model2 = gr.Model3D( | |
label="Output Model", | |
interactive=False, | |
) | |
with gr.Tab("glb"): | |
output_model2 = gr.Model3D( | |
label="Output Model", | |
interactive=False, | |
) | |
with gr.Column(): | |
gr.Markdown("**Output Models**") | |
output_model = gr.Model3D(label="Output Model", interactive=False) | |
output_model2 = gr.Model3D(label="Output Model", interactive=False) | |
with gr.Row(): | |
#... | |
with gr.Button("Download Example", elem_id="download_example", fn=partial(run_example, inputs=[input_image], outputs=[input_image, output_model]): | |
#... | |
with gr.Column(): | |
gr.Examples( | |
examples=[ | |
"examples/1.png", | |
"examples/2.png", | |
], | |
inputs=[input_image], | |
outputs=[output_model, output_model2], | |
fn=partial(run_example), | |
label="Examples", | |
examples_per_page=20, | |
) | |
submit.click( | |
fn=partial(run_example), | |
inputs=[input_image], | |
outputs=[output_model, output_model2], | |
) | |
with gr.Button("Generate", elem_id="generate", variant="primary", fn=generate, inputs=[output_model, output_model2]): | |
#... | |
with gr.Row(): | |
output_model = gr.Model3D( | |
label="Output Model", | |
interactive=False, | |
) | |
output_model2 = gr.Model3D( | |
label="Output Model", | |
interactive=False, | |
) | |
) | |
with gr.Column(): | |
gr.Markdown("**Input Image**") | |
input_image = gr.Image( | |
label="", | |
image_mode="RGBA", | |
sources="upload", | |
type="pil", | |
elem_id="content_image", | |
width=500, # Увеличена ширина входных изображений | |
) | |
with gr.Column(): | |
do_remove_background = gr.Checkbox( | |
label="Remove Background", | |
value=True, | |
elem_id="remove_background", | |
) | |
foreground_ratio = gr.Slider( | |
label="Foreground Ratio", | |
minimum=0.5, | |
maximum=1.0, | |
value=0.85, | |
step=0.05, | |
elem_id="foreground_ratio", | |
) | |
with gr.Row(): | |
submit = gr.Button( | |
label="Generate", | |
scale=0, | |
variant="primary", | |
elem_classes="generate-button", | |
) | |
output_model = gr.Model3D( | |
label="Output Model", | |
interactive=False, | |
) | |
output_model2 |