guigonzalez commited on
Commit
bd3a53e
·
verified ·
1 Parent(s): 4fc89cc

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +1 -1
  2. app.py +57 -66
  3. requirements.txt +2 -2
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 🎨
4
  colorFrom: blue
5
  colorTo: purple
6
  sdk: gradio
7
- sdk_version: 4.36.1
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
4
  colorFrom: blue
5
  colorTo: purple
6
  sdk: gradio
7
+ sdk_version: 4.0.2
8
  app_file: app.py
9
  pinned: false
10
  license: mit
app.py CHANGED
@@ -196,75 +196,66 @@ def generate_3d(
196
  return output_path
197
 
198
 
199
- # Interface Gradio
200
- with gr.Blocks(title="TripoSG 3D Generator") as demo:
201
- gr.Markdown("""
202
- # 🎨 TripoSG 3D Generator
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  Gere modelos 3D a partir de imagens usando [TripoSG](https://github.com/VAST-AI-Research/TripoSG).
205
 
206
- **Dicas:**
207
- - Use imagens com objeto centralizado
208
- - Fundo limpo ou use "Remover fundo"
209
- - Mais passos = melhor qualidade (mais lento)
210
- """)
211
-
212
- with gr.Row():
213
- with gr.Column(scale=1):
214
- input_image = gr.Image(
215
- label="Imagem de Entrada",
216
- type="pil",
217
- height=400,
218
- )
219
-
220
- with gr.Accordion("Configurações", open=True):
221
- remove_bg = gr.Checkbox(
222
- label="Remover fundo automaticamente",
223
- value=True,
224
- )
225
- num_steps = gr.Slider(
226
- label="Passos de inferência",
227
- minimum=20,
228
- maximum=100,
229
- value=50,
230
- step=5,
231
- )
232
- guidance_scale = gr.Slider(
233
- label="Guidance Scale",
234
- minimum=1.0,
235
- maximum=15.0,
236
- value=7.0,
237
- step=0.5,
238
- )
239
- seed = gr.Number(
240
- label="Seed (reprodutibilidade)",
241
- value=42,
242
- precision=0,
243
- )
244
- output_format = gr.Radio(
245
- label="Formato de saída",
246
- choices=["glb", "stl"],
247
- value="glb",
248
- )
249
-
250
- generate_btn = gr.Button("🚀 Gerar Modelo 3D", variant="primary", size="lg")
251
-
252
- with gr.Column(scale=1):
253
- # Usar File ao invés de Model3D para evitar bug de schema no HF Spaces
254
- output_file = gr.File(label="Modelo 3D Gerado")
255
- gr.Markdown("*Baixe o arquivo GLB/STL e visualize em um viewer 3D online como [glTF Viewer](https://gltf-viewer.donmccurdy.com/)*")
256
-
257
- generate_btn.click(
258
- fn=generate_3d,
259
- inputs=[input_image, num_steps, guidance_scale, seed, remove_bg, output_format],
260
- outputs=output_file,
261
- )
262
-
263
- gr.Markdown("""
264
- ---
265
- **Powered by:** [TripoSG](https://github.com/VAST-AI-Research/TripoSG) |
266
- [RMBG-1.4](https://huggingface.co/briaai/RMBG-1.4)
267
- """)
268
 
269
 
270
  if __name__ == "__main__":
 
196
  return output_path
197
 
198
 
199
+ # Interface Gradio - usando Interface simples para evitar bugs de schema
200
+ def generate_wrapper(image, num_steps, guidance_scale, seed, remove_bg, output_format):
201
+ """Wrapper para a função generate_3d sem progress."""
202
+ if image is None:
203
+ raise gr.Error("Por favor, faça upload de uma imagem.")
204
+
205
+ # Remover fundo se necessário
206
+ if remove_bg:
207
+ image = remove_background(image)
208
+
209
+ # Redimensionar para 512x512
210
+ image = image.resize((512, 512), Image.LANCZOS)
211
+
212
+ # Gerar
213
+ generator = torch.Generator(device=DEVICE).manual_seed(int(seed))
214
+
215
+ with torch.no_grad():
216
+ outputs = pipe(
217
+ image=image,
218
+ generator=generator,
219
+ num_inference_steps=int(num_steps),
220
+ guidance_scale=float(guidance_scale),
221
+ use_flash_decoder=False,
222
+ )
223
+
224
+ # Salvar mesh
225
+ mesh = outputs.meshes[0]
226
+
227
+ with tempfile.NamedTemporaryFile(suffix=f".{output_format}", delete=False) as f:
228
+ output_path = f.name
229
+
230
+ if output_format == "glb":
231
+ mesh.export(output_path)
232
+ else:
233
+ mesh.export(output_path, file_type="stl")
234
+
235
+ return output_path
236
+
237
 
238
+ demo = gr.Interface(
239
+ fn=generate_wrapper,
240
+ inputs=[
241
+ gr.Image(label="Imagem de Entrada", type="pil"),
242
+ gr.Slider(label="Passos de inferência", minimum=20, maximum=100, value=50, step=5),
243
+ gr.Slider(label="Guidance Scale", minimum=1.0, maximum=15.0, value=7.0, step=0.5),
244
+ gr.Number(label="Seed", value=42, precision=0),
245
+ gr.Checkbox(label="Remover fundo automaticamente", value=True),
246
+ gr.Radio(label="Formato de saída", choices=["glb", "stl"], value="glb"),
247
+ ],
248
+ outputs=gr.File(label="Modelo 3D Gerado"),
249
+ title="🎨 TripoSG 3D Generator",
250
+ description="""
251
  Gere modelos 3D a partir de imagens usando [TripoSG](https://github.com/VAST-AI-Research/TripoSG).
252
 
253
+ **Dicas:** Use imagens com objeto centralizado. Mais passos = melhor qualidade (mais lento).
254
+
255
+ Baixe o arquivo e visualize em [glTF Viewer](https://gltf-viewer.donmccurdy.com/)
256
+ """,
257
+ allow_flagging="never",
258
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
 
260
 
261
  if __name__ == "__main__":
requirements.txt CHANGED
@@ -23,7 +23,7 @@ scipy
23
  trimesh
24
  numpy>=1.22.3,<2.0.0
25
 
26
- # Interface - usar versão estável do Gradio (4.36.1 não tem bug do schema)
27
- gradio==4.36.1
28
 
29
  # Nota: TripoSG será clonado via app.py (não é um pacote pip)
 
23
  trimesh
24
  numpy>=1.22.3,<2.0.0
25
 
26
+ # Interface - usar versão antiga do Gradio sem bug de schema
27
+ gradio==4.0.2
28
 
29
  # Nota: TripoSG será clonado via app.py (não é um pacote pip)