naohiro701 commited on
Commit
410acfd
·
verified ·
1 Parent(s): 352de3d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -2,21 +2,27 @@ import gradio as gr
2
  import trimesh
3
  import tempfile
4
  import os
5
- import shutil
6
 
7
  def convert(input_path_str):
8
  with tempfile.TemporaryDirectory() as tmpdir:
9
- input_path = input_path_str # already a path
10
  output_path = os.path.join(tmpdir, "output.glb")
11
 
12
  mesh = trimesh.load(input_path, force='mesh')
 
 
 
 
13
  mesh.export(output_path, file_type='glb')
14
 
 
 
 
15
  return output_path
16
 
17
  demo = gr.Interface(
18
  fn=convert,
19
- inputs=gr.File(file_types=[".obj"], type="filepath"), # type="filepath" is default
20
  outputs=gr.File(file_types=[".glb"]),
21
  title="OBJ to glTF (.glb) Converter"
22
  )
 
2
  import trimesh
3
  import tempfile
4
  import os
 
5
 
6
  def convert(input_path_str):
7
  with tempfile.TemporaryDirectory() as tmpdir:
8
+ input_path = input_path_str
9
  output_path = os.path.join(tmpdir, "output.glb")
10
 
11
  mesh = trimesh.load(input_path, force='mesh')
12
+
13
+ if mesh.is_empty:
14
+ raise ValueError("Invalid or empty OBJ mesh.")
15
+
16
  mesh.export(output_path, file_type='glb')
17
 
18
+ if not os.path.exists(output_path):
19
+ raise FileNotFoundError("Export failed: output.glb not created.")
20
+
21
  return output_path
22
 
23
  demo = gr.Interface(
24
  fn=convert,
25
+ inputs=gr.File(file_types=[".obj"], type="filepath"),
26
  outputs=gr.File(file_types=[".glb"]),
27
  title="OBJ to glTF (.glb) Converter"
28
  )