proki-demo / app.py
ifw-arz's picture
tok
edd8879
raw
history blame
5.08 kB
import streamlit as st
import sys
import os
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import torch
import numpy as np
import threading
import hmac
from processing.surface_plots import surface_plot
from processing.preprocessing import plot_timeseries
from processing.prediction import NN_prediction
from processing.classification_model import classify
from processing.barsplots_rootcauses import check_classification
from processing.cloud_access import auto_download
sprint_data_folder = "Messungen"
def get_csv_files(data_folder):
csv_files = []
for file in os.listdir(data_folder):
if file.endswith(".csv"):
csv_file = os.path.join(data_folder, file)
csv_files.append(csv_file)
return csv_files
def check_password():
"""Returns `True` if the user had the correct password."""
def password_entered():
"""Checks whether a password entered by the user is correct."""
if hmac.compare_digest(st.session_state["password"], os.getenv("Password")):
st.session_state["password_correct"] = True
del st.session_state["password"] # Don't store the password.
else:
st.session_state["password_correct"] = False
# Return True if the password is validated.
if st.session_state.get("password_correct", False):
return True
# Show input for password.
st.text_input(
"Password", type="password", on_change=password_entered, key="password"
)
if "password_correct" in st.session_state:
st.error("😕 Password incorrect")
return False
if not check_password():
st.stop() # Do not continue if check_password is not True.
def main():
sprint_csv_files = get_csv_files(sprint_data_folder)
st.set_page_config(page_title="Assistenzsystem", page_icon=":eyeglasses:", layout="wide")
with open("assets/style.css") as f:
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
st.write("")
col1, col2 = st.columns([0.5, 1])
with col1: st.image("assets/ProKI_Logo.png", width=200)
with col2: st.markdown("<h2 style='text-align: left; color: black; font-family:Arial;font-size:2.25rem;'>Assistenzsystem</h2>", unsafe_allow_html=True)
tab1, tab2 = st.tabs(["Modellierung der Bauteilqualität", "Klassifizierungsergebnisse"])
with tab1:
st.markdown("#")
col1, col2, col3 = st.columns([0.5, 0.1, 0.4], gap="large")
with col1:
feed = st.slider("Vorschub [mm/min]", 400, 1300, 850)
plaindepth = st.slider("Schnitttiefe [mm]", 0.1, 0.5, 0.3)
wear = st.slider("Werkzeugverschleiß %", 0, 100, 50)
try:
fig = NN_prediction((feed-400)/900, (plaindepth-0.1)/0.4, wear/100)
st.pyplot(fig)
except:
st.write("Models not loaded yet")
with col2:
st.write("")
with col3:
st.write("")
st.image("assets/slice.png", width=400)
auswahl = st.radio("Merkmal", ["Vorschub", "Schnitttiefe", "Werkzeugverschleiß"], horizontal=True, index=0)
width = 500
if auswahl == "Vorschub":
st.image("assets/max_Vorschub.PNG", width=width)
elif auswahl == "Schnitttiefe":
st.image("assets/max_Schnitttiefe.PNG", width=width)
else:
st.image("assets/max_Verschleiß.PNG", width=width)
with tab2:
selected_file = st.selectbox("Oberflächenscan auswählen", sprint_csv_files, 0)
col1, col_blanc, col2= st.columns([0.45, 0.1, 0.45], gap="large")
with col1:
try:
fig = surface_plot(selected_file)
fig.update_layout(height=800, width=1200)
st.plotly_chart(fig, theme="streamlit", use_container_width=False)
except:
pass
with col_blanc:
st.write("")
with col2:
st.markdown("<h2 style='text-align: center; color: black; font-family:Arial;font-size:2rem;'>Klassifizierung</h2>", unsafe_allow_html=True)
st.markdown("#")
dummy, tolerance, z_data, fivetothirty = plot_timeseries(selected_file, 9)
data = fivetothirty["z"].values
mean = np.mean(data)
data = data - mean
try:
data = torch.tensor(data, dtype=torch.float).to("cpu")
data = data.view(1,1,500)
prediction = classify(data)
fig_feed, fig_depth, fig_condition = check_classification(prediction[0])
st.pyplot(fig_feed)
st.pyplot(fig_depth)
st.pyplot(fig_condition)
except:
st.write("Models not loaded yet")
if __name__ == "__main__":
main()
t1 = threading.Thread(target=auto_download(os.getenv("seafile_token")))
t1.start()