Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
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=[],
|