Spaces:
Runtime error
Runtime error
SHAMIL SHAHBAZ AWAN commited on
Create app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748import streamlit as stfrom stl import meshfrom mpl_toolkits import mplot3dimport matplotlib.pyplot as pltimport tempfileimport os
# Page configurationst.set_page_config(page_title="AR CAD Viewer", layout="wide")
# Titlest.title("Augmented Reality CAD Viewer")st.write("Upload your CAD models and view them in a 3D interactive environment.")
# File uploader for CAD filesuploaded_file = st.file_uploader("Upload a CAD file (.stl format)", type=["stl"])
if uploaded_file is not None: # Save uploaded file to a temporary location with tempfile.NamedTemporaryFile(delete=False, suffix=".stl") as temp_file: temp_file.write(uploaded_file.read()) temp_filepath = temp_file.name # Load the STL file stl_mesh = mesh.Mesh.from_file(temp_filepath) # Create a new figure for plotting fig = plt.figure(figsize=(10, 10)) ax = fig.add_subplot(111, projection="3d") # Plot the CAD model ax.add_collection3d(mplot3d.art3d.Poly3DCollection(stl_mesh.vectors, alpha=0.7, color="cyan")) ax.auto_scale_xyz(stl_mesh.points.flatten(), stl_mesh.points.flatten(), stl_mesh.points.flatten()) # Display the 3D plot in Streamlit st.pyplot(fig) # Clean up the temporary file os.remove(temp_filepath)
# AR.js linkst.markdown( """ ## AR Feature Use [AR.js](https://ar-js-org.github.io/AR.js/) to host your model online for AR visualization. Upload this model to a compatible AR hosting service or modify the file to be AR.js-ready. """)app.pyAdded+48