Rahatara commited on
Commit
d9e65b3
·
verified ·
1 Parent(s): 08a9319

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -3,6 +3,8 @@ from pygltflib import GLTF2, Texture, Image
3
  import base64
4
  import io
5
 
 
 
6
  def modify_texture():
7
  # Load the GLB file
8
  glb = GLTF2().load("train.glb")
@@ -22,12 +24,18 @@ def modify_texture():
22
  default_texture = Texture(source=len(glb.images)-1)
23
  glb.textures.append(default_texture)
24
 
25
- # Save the modified GLB to a temporary file and return it
26
- output_file = io.BytesIO()
27
- glb.save(output_file)
28
- output_file.seek(0)
 
 
 
 
 
29
  return output_file
30
 
 
31
  gr.Interface(
32
  fn=modify_texture,
33
  inputs=[],
 
3
  import base64
4
  import io
5
 
6
+ import tempfile
7
+
8
  def modify_texture():
9
  # Load the GLB file
10
  glb = GLTF2().load("train.glb")
 
24
  default_texture = Texture(source=len(glb.images)-1)
25
  glb.textures.append(default_texture)
26
 
27
+ # Save the modified GLB to a temporary file
28
+ with tempfile.NamedTemporaryFile(suffix=".glb", delete=False) as tmp_file:
29
+ tmp_filename = tmp_file.name
30
+ glb.save(tmp_filename)
31
+
32
+ # Read the temporary file back into memory as BytesIO
33
+ with open(tmp_filename, "rb") as tmp_file:
34
+ output_file = io.BytesIO(tmp_file.read())
35
+
36
  return output_file
37
 
38
+
39
  gr.Interface(
40
  fn=modify_texture,
41
  inputs=[],