, resolution=mc_resolution
Browse files
app.py
CHANGED
@@ -17,7 +17,6 @@ from tsr.utils import remove_background, resize_foreground, to_gradio_3d_orienta
|
|
17 |
|
18 |
HEADER = """
|
19 |
**TripoSR** is a state-of-the-art open-source model for **fast** feedforward 3D reconstruction from a single image, developed in collaboration between [Tripo AI](https://www.tripo3d.ai/) and [Stability AI](https://stability.ai/).
|
20 |
-
|
21 |
**Tips:**
|
22 |
1. If you find the result is unsatisfied, please try to change the foreground ratio. It might improve the results.
|
23 |
2. Please disable "Remove Background" option only if your input image is RGBA with transparent background, image contents are centered and occupy more than 70% of image width or height.
|
@@ -69,16 +68,15 @@ def preprocess(input_image, do_remove_background, foreground_ratio):
|
|
69 |
return image
|
70 |
|
71 |
|
72 |
-
def generate(image, mc_resolution
|
73 |
scene_codes = model(image, device=device)
|
74 |
mesh = model.extract_mesh(scene_codes, resolution=mc_resolution)[0]
|
75 |
mesh = to_gradio_3d_orientation(mesh)
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
return rv
|
82 |
|
83 |
def run_example(image_pil):
|
84 |
preprocessed = preprocess(image_pil, False, 0.9)
|
@@ -121,12 +119,12 @@ with gr.Blocks() as demo:
|
|
121 |
submit = gr.Button("Generate", elem_id="generate", variant="primary")
|
122 |
with gr.Column():
|
123 |
with gr.Tab("obj"):
|
124 |
-
|
125 |
label="Output Model",
|
126 |
interactive=False,
|
127 |
)
|
128 |
with gr.Tab("glb"):
|
129 |
-
|
130 |
label="Output Model",
|
131 |
interactive=False,
|
132 |
)
|
@@ -136,7 +134,7 @@ with gr.Blocks() as demo:
|
|
136 |
os.path.join("examples", img_name) for img_name in sorted(os.listdir("examples"))
|
137 |
],
|
138 |
inputs=[input_image],
|
139 |
-
outputs=[processed_image,
|
140 |
#cache_examples=True,
|
141 |
fn=partial(run_example),
|
142 |
label="Examples",
|
@@ -149,8 +147,8 @@ with gr.Blocks() as demo:
|
|
149 |
).success(
|
150 |
fn=generate,
|
151 |
inputs=[processed_image, mc_resolution],
|
152 |
-
outputs=[
|
153 |
)
|
154 |
|
155 |
demo.queue(max_size=10)
|
156 |
-
demo.launch()
|
|
|
17 |
|
18 |
HEADER = """
|
19 |
**TripoSR** is a state-of-the-art open-source model for **fast** feedforward 3D reconstruction from a single image, developed in collaboration between [Tripo AI](https://www.tripo3d.ai/) and [Stability AI](https://stability.ai/).
|
|
|
20 |
**Tips:**
|
21 |
1. If you find the result is unsatisfied, please try to change the foreground ratio. It might improve the results.
|
22 |
2. Please disable "Remove Background" option only if your input image is RGBA with transparent background, image contents are centered and occupy more than 70% of image width or height.
|
|
|
68 |
return image
|
69 |
|
70 |
|
71 |
+
def generate(image, mc_resolution):
|
72 |
scene_codes = model(image, device=device)
|
73 |
mesh = model.extract_mesh(scene_codes, resolution=mc_resolution)[0]
|
74 |
mesh = to_gradio_3d_orientation(mesh)
|
75 |
+
mesh_path = tempfile.NamedTemporaryFile(suffix=".obj", delete=False)
|
76 |
+
mesh_path2 = tempfile.NamedTemporaryFile(suffix=".glb", delete=False)
|
77 |
+
mesh.export(mesh_path.name)
|
78 |
+
mesh.export(mesh_path2.name)
|
79 |
+
return mesh_path.name, mesh_path2.name
|
|
|
80 |
|
81 |
def run_example(image_pil):
|
82 |
preprocessed = preprocess(image_pil, False, 0.9)
|
|
|
119 |
submit = gr.Button("Generate", elem_id="generate", variant="primary")
|
120 |
with gr.Column():
|
121 |
with gr.Tab("obj"):
|
122 |
+
output_model = gr.Model3D(
|
123 |
label="Output Model",
|
124 |
interactive=False,
|
125 |
)
|
126 |
with gr.Tab("glb"):
|
127 |
+
output_model2 = gr.Model3D(
|
128 |
label="Output Model",
|
129 |
interactive=False,
|
130 |
)
|
|
|
134 |
os.path.join("examples", img_name) for img_name in sorted(os.listdir("examples"))
|
135 |
],
|
136 |
inputs=[input_image],
|
137 |
+
outputs=[processed_image, output_model, output_model2],
|
138 |
#cache_examples=True,
|
139 |
fn=partial(run_example),
|
140 |
label="Examples",
|
|
|
147 |
).success(
|
148 |
fn=generate,
|
149 |
inputs=[processed_image, mc_resolution],
|
150 |
+
outputs=[output_model, output_model2],
|
151 |
)
|
152 |
|
153 |
demo.queue(max_size=10)
|
154 |
+
demo.launch()
|