-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstreamlit_app.py
33 lines (28 loc) · 959 Bytes
/
streamlit_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import tempfile
import streamlit as st
import pyvista as pv
from pyvista import examples
st.sidebar.title("STL viewer")
uploaded_file = st.file_uploader("Upload a STL:", ["stl"], False)
if uploaded_file:
with tempfile.NamedTemporaryFile(suffix=".stl") as fp:
fp.write(uploaded_file.getbuffer())
reader = pv.STLReader(fp.name)
mesh = reader.read()
else:
mesh = examples.download_bunny()
plotter = pv.Plotter(window_size=[800, 600])
plotter.background_color = st.sidebar.color_picker(
"Background color of this renderer.", "#000000"
)
plotter.add_mesh(
mesh,
color=st.sidebar.color_picker(
"Use to make the entire mesh have a single solid color.", "#00f900"
),
)
with tempfile.NamedTemporaryFile(suffix=".html") as fp:
other = plotter.export_html(fp.name, backend="pythreejs")
with open(fp.name, "r") as f:
model = f.read()
st.components.v1.html(model, width=800, height=600)