Spaces:
Runtime error
Runtime error
SHAMIL SHAHBAZ AWAN
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,10 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
| 2 |
from stl import mesh
|
| 3 |
-
from mpl_toolkits import mplot3d
|
| 4 |
-
import matplotlib.pyplot as plt
|
| 5 |
import tempfile
|
| 6 |
import os
|
| 7 |
import trimesh
|
| 8 |
-
import pyvista as pv
|
| 9 |
|
| 10 |
# Page configuration
|
| 11 |
st.set_page_config(page_title="AR CAD Viewer", layout="wide")
|
|
@@ -23,16 +22,19 @@ if uploaded_file is not None:
|
|
| 23 |
temp_file.write(uploaded_file.read())
|
| 24 |
temp_filepath = temp_file.name
|
| 25 |
|
| 26 |
-
# Load the STL file
|
| 27 |
-
stl_mesh = mesh.Mesh.from_file(temp_filepath)
|
| 28 |
-
|
| 29 |
-
# Preview the model in 3D
|
| 30 |
st.subheader("3D Model Preview")
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
# Convert to glTF for AR
|
| 38 |
st.subheader("Convert to AR Format")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
import pyvista as pv
|
| 4 |
from stl import mesh
|
|
|
|
|
|
|
| 5 |
import tempfile
|
| 6 |
import os
|
| 7 |
import trimesh
|
|
|
|
| 8 |
|
| 9 |
# Page configuration
|
| 10 |
st.set_page_config(page_title="AR CAD Viewer", layout="wide")
|
|
|
|
| 22 |
temp_file.write(uploaded_file.read())
|
| 23 |
temp_filepath = temp_file.name
|
| 24 |
|
| 25 |
+
# Load the STL file using pyvista for interactive 3D rendering
|
|
|
|
|
|
|
|
|
|
| 26 |
st.subheader("3D Model Preview")
|
| 27 |
+
|
| 28 |
+
# Load the STL using pyvista
|
| 29 |
+
mesh_data = pv.read(temp_filepath)
|
| 30 |
+
|
| 31 |
+
# Create the plotter and add the mesh to it
|
| 32 |
+
plotter = pv.Plotter(off_screen=True)
|
| 33 |
+
plotter.add_mesh(mesh_data, color="cyan")
|
| 34 |
+
plotter.view_isometric()
|
| 35 |
+
|
| 36 |
+
# Show the plot in the Streamlit app
|
| 37 |
+
st.pydeck_chart(plotter.show())
|
| 38 |
|
| 39 |
# Convert to glTF for AR
|
| 40 |
st.subheader("Convert to AR Format")
|