michaelj commited on
Commit
d7d97a4
·
verified ·
1 Parent(s): 90c653a

, resolution=mc_resolution

Browse files
Files changed (1) hide show
  1. app.py +11 -13
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, formats=["obj", "glb"]):
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
- rv = []
77
- for format in formats:
78
- mesh_path = tempfile.NamedTemporaryFile(suffix=f".{format}", delete=False)
79
- mesh.export(mesh_path.name)
80
- rv.append(mesh_path.name)
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
- output_model_obj = gr.Model3D(
125
  label="Output Model",
126
  interactive=False,
127
  )
128
  with gr.Tab("glb"):
129
- output_model_glb = gr.Model3D(
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, output_model_obj, output_model_glb],
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=[output_model_obj, output_model_glb],
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()