dschandra commited on
Commit
afe1c50
·
verified ·
1 Parent(s): 5539974

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import open3d as o3d
2
+ import streamlit as st
3
+
4
+ # Streamlit title and description
5
+ st.title("Jewelry 3D Model Viewer")
6
+ st.write("Upload an OBJ file to visualize the 3D model of jewelry.")
7
+
8
+ # File uploader for the OBJ file
9
+ uploaded_file = st.file_uploader("Choose an OBJ file", type="obj")
10
+
11
+ if uploaded_file is not None:
12
+ # Save the uploaded file to a temporary location
13
+ with open("uploaded_model.obj", "wb") as f:
14
+ f.write(uploaded_file.getbuffer())
15
+
16
+ # Load the mesh using Open3D
17
+ mesh = o3d.io.read_triangle_mesh("uploaded_model.obj")
18
+ mesh.compute_vertex_normals()
19
+
20
+ # Convert the mesh to a visualizable format for Streamlit
21
+ vertices = mesh.vertices
22
+ triangles = mesh.triangles
23
+ vertex_colors = mesh.vertex_colors
24
+
25
+ st.write("### 3D Model Preview")
26
+ st.write("Mesh Vertices: ", len(vertices))
27
+ st.write("Mesh Triangles: ", len(triangles))
28
+
29
+ # Display the 3D mesh using Streamlit's 3D visualization support
30
+ st.write("You can download Open3D and use it to visualize the mesh locally.")
31
+
32
+ # Optionally, display the mesh information
33
+ st.write(mesh)
34
+
35
+ else:
36
+ st.write("Please upload an OBJ file to visualize the jewelry model.")