Mathdesenvnonimate commited on
Commit
638d3bd
·
verified ·
1 Parent(s): 85456b1

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -48
app.py CHANGED
@@ -20,41 +20,10 @@ from tsr.utils import remove_background, resize_foreground, to_gradio_3d_orienta
20
 
21
 
22
  HEADER = """
23
- # TripoSR Demo
24
- <table bgcolor="#1E2432" cellspacing="0" cellpadding="0" width="450">
25
- <tr style="height:50px;">
26
- <td style="text-align: center;">
27
- <a href="https://stability.ai">
28
- <img src="https://images.squarespace-cdn.com/content/v1/6213c340453c3f502425776e/6c9c4c25-5410-4547-bc26-dc621cdacb25/Stability+AI+logo.png" width="200" height="40" />
29
- </a>
30
- </td>
31
- <td style="text-align: center;">
32
- <a href="https://www.tripo3d.ai">
33
- <img src="https://tripo-public.cdn.bcebos.com/logo.png" width="40" height="40" />
34
- </a>
35
- </td>
36
- </tr>
37
- </table>
38
- <table bgcolor="#1E2432" cellspacing="0" cellpadding="0" width="450">
39
- <tr style="height:30px;">
40
- <td style="text-align: center;">
41
- <a href="https://huggingface.co/stabilityai/TripoSR"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Model_Card-Huggingface-orange" height="20"></a>
42
- </td>
43
- <td style="text-align: center;">
44
- <a href="https://github.com/VAST-AI-Research/TripoSR"><img src="https://postimage.me/images/2024/03/04/GitHub_Logo_White.png" width="100" height="20"></a>
45
- </td>
46
- <td style="text-align: center; color: white;">
47
- <a href="https://arxiv.org/abs/2403.02151"><img src="https://img.shields.io/badge/arXiv-2403.02151-b31b1b.svg" height="20"></a>
48
- </td>
49
- </tr>
50
- </table>
51
-
52
- **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/).
53
-
54
- **Tips:**
55
- 1. If you find the result is unsatisfied, please try to change the foreground ratio. It might improve the results.
56
- 2. It's better to disable "Remove Background" for the provided examples since they have been already preprocessed.
57
- 3. Otherwise, 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.
58
  """
59
 
60
 
@@ -76,7 +45,7 @@ rembg_session = rembg.new_session()
76
 
77
  def check_input_image(input_image):
78
  if input_image is None:
79
- raise gr.Error("No image uploaded!")
80
 
81
 
82
  def preprocess(input_image, do_remove_background, foreground_ratio):
@@ -159,7 +128,7 @@ def preprocess(input_image, do_remove_background, foreground_ratio):
159
  image = fill_background(image)
160
  return image
161
 
162
-
163
  def fill_background(image):
164
  image = np.array(image).astype(np.float32) / 255.0
165
  image = image[:, :, :3] * image[:, :, 3:4] + (1 - image[:, :, 3:4]) * 0.5
@@ -210,21 +179,21 @@ with gr.Blocks() as demo:
210
  type="pil",
211
  elem_id="content_image",
212
  )
213
- processed_image = gr.Image(label="Processed Image", interactive=False)
214
  with gr.Row():
215
  with gr.Group():
216
  do_remove_background = gr.Checkbox(
217
- label="Remove Background", value=True
218
  )
219
  foreground_ratio = gr.Slider(
220
- label="Foreground Ratio",
221
  minimum=0.5,
222
  maximum=1.0,
223
  value=0.85,
224
  step=0.05,
225
  )
226
  mc_resolution = gr.Slider(
227
- label="Marching Cubes Resolution",
228
  minimum=32,
229
  maximum=320,
230
  value=256,
@@ -235,16 +204,16 @@ with gr.Blocks() as demo:
235
  with gr.Column():
236
  with gr.Tab("OBJ"):
237
  output_model_obj = gr.Model3D(
238
- label="Output Model (OBJ Format)",
239
  interactive=False,
240
  )
241
- gr.Markdown("Note: Downloaded object will be flipped in case of .obj export. Export .glb instead or manually flip it before usage.")
242
- with gr.Tab("GLB"):
243
  output_model_glb = gr.Model3D(
244
- label="Output Model (GLB Format)",
245
  interactive=False,
246
  )
247
- gr.Markdown("Note: The model shown here has a darker appearance. Download to get correct results.")
248
  with gr.Row(variant="panel"):
249
  gr.Examples(
250
  examples=[
@@ -253,8 +222,6 @@ with gr.Blocks() as demo:
253
  inputs=[input_image],
254
  outputs=[processed_image, output_model_obj, output_model_glb],
255
  cache_examples=True,
256
- fn=partial(run_example),
257
- label="Examples",
258
  examples_per_page=20
259
  )
260
  submit.click(fn=check_input_image, inputs=[input_image]).success(
 
20
 
21
 
22
  HEADER = """
23
+ # 3D
24
+ 1. Se você achar que o resultado não é satisfatório, tente alterar a proporção do primeiro plano. Pode melhorar os resultados.
25
+ 2. É melhor desabilitar "Remover plano de fundo" para os exemplos fornecidos, pois eles já foram pré-processados.
26
+ 3. Caso contrário, desative a opção "Remover plano de fundo" somente se sua imagem de entrada for RGBA com fundo transparente, o conteúdo da imagem estiver centralizado e ocupar mais de 70% da largura ou altura da imagem.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  """
28
 
29
 
 
45
 
46
  def check_input_image(input_image):
47
  if input_image is None:
48
+ raise gr.Error("Nenhuma Imagem Carregada!")
49
 
50
 
51
  def preprocess(input_image, do_remove_background, foreground_ratio):
 
128
  image = fill_background(image)
129
  return image
130
 
131
+
132
  def fill_background(image):
133
  image = np.array(image).astype(np.float32) / 255.0
134
  image = image[:, :, :3] * image[:, :, 3:4] + (1 - image[:, :, 3:4]) * 0.5
 
179
  type="pil",
180
  elem_id="content_image",
181
  )
182
+ processed_image = gr.Image(label="Imagem Processada", interactive=False)
183
  with gr.Row():
184
  with gr.Group():
185
  do_remove_background = gr.Checkbox(
186
+ label="Remover Background", value=True
187
  )
188
  foreground_ratio = gr.Slider(
189
+ label="Proporção de Primeiro Plano",
190
  minimum=0.5,
191
  maximum=1.0,
192
  value=0.85,
193
  step=0.05,
194
  )
195
  mc_resolution = gr.Slider(
196
+ label="Marching Cubes Resolução",
197
  minimum=32,
198
  maximum=320,
199
  value=256,
 
204
  with gr.Column():
205
  with gr.Tab("OBJ"):
206
  output_model_obj = gr.Model3D(
207
+ label="Saida do Modelo (OBJ Format)",
208
  interactive=False,
209
  )
210
+ gr.Markdown("")
211
+ with gr.Tab("STL"):
212
  output_model_glb = gr.Model3D(
213
+ label="Saída do Modelo (STL Format)",
214
  interactive=False,
215
  )
216
+ gr.Markdown("Nota: O modelo mostrado aqui tem uma aparência mais escura. Baixe para obter resultados corretos.")
217
  with gr.Row(variant="panel"):
218
  gr.Examples(
219
  examples=[
 
222
  inputs=[input_image],
223
  outputs=[processed_image, output_model_obj, output_model_glb],
224
  cache_examples=True,
 
 
225
  examples_per_page=20
226
  )
227
  submit.click(fn=check_input_image, inputs=[input_image]).success(