SHAMIL SHAHBAZ AWAN commited on
Commit
68c04e9
·
verified ·
1 Parent(s): 9719d61

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
8
+ # Page configuration
9
+ st.set_page_config(page_title="AR CAD Viewer", layout="wide")
10
+
11
+ # Title
12
+ st.title("Augmented Reality CAD Viewer")
13
+ st.write("Upload your CAD models and view them in a 3D interactive environment.")
14
+
15
+ # File uploader for CAD files
16
+ uploaded_file = st.file_uploader("Upload a CAD file (.stl format)", type=["stl"])
17
+
18
+ if uploaded_file is not None:
19
+ # Save uploaded file to a temporary location
20
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".stl") as temp_file:
21
+ temp_file.write(uploaded_file.read())
22
+ temp_filepath = temp_file.name
23
+
24
+ # Load the STL file
25
+ stl_mesh = mesh.Mesh.from_file(temp_filepath)
26
+
27
+ # Create a new figure for plotting
28
+ fig = plt.figure(figsize=(10, 10))
29
+ ax = fig.add_subplot(111, projection="3d")
30
+
31
+ # Plot the CAD model
32
+ ax.add_collection3d(mplot3d.art3d.Poly3DCollection(stl_mesh.vectors, alpha=0.7, color="cyan"))
33
+ ax.auto_scale_xyz(stl_mesh.points.flatten(), stl_mesh.points.flatten(), stl_mesh.points.flatten())
34
+
35
+ # Display the 3D plot in Streamlit
36
+ st.pyplot(fig)
37
+
38
+ # Clean up the temporary file
39
+ os.remove(temp_filepath)
40
+
41
+ # AR.js link
42
+ st.markdown(
43
+ """
44
+ ## AR Feature
45
+ Use [AR.js](https://ar-js-org.github.io/AR.js/) to host your model online for AR visualization.
46
+ Upload this model to a compatible AR hosting service or modify the file to be AR.js-ready.
47
+ """
48
+ )