Rahatara commited on
Commit
c79165d
·
verified ·
1 Parent(s): 58cb069

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import trimesh
3
+ import base64
4
+ import io
5
+
6
+ def modify_texture():
7
+ # Load the GLB file
8
+ mesh = trimesh.load("train.glb")
9
+
10
+ # Load the default texture image
11
+ with open("defect.jpg", "rb") as f:
12
+ default_texture_data = f.read()
13
+
14
+ # Set the texture to the mesh
15
+ mesh.visual.material.texture.image = default_texture_data
16
+
17
+ # Export the modified mesh to GLB format
18
+ modified_mesh_data = mesh.export(file_type="glb")
19
+
20
+ # Convert the modified mesh data to BytesIO object
21
+ output_file = io.BytesIO(modified_mesh_data)
22
+
23
+ return output_file
24
+
25
+ gr.Interface(
26
+ fn=modify_texture,
27
+ inputs=[],
28
+ outputs=gr.outputs.File(label="Download Modified GLB File"),
29
+ title="GLB Texture Modifier"
30
+ ).launch()