I’m relatively new to streamlit and I’m building an app that takes a csv of signals, extracts the column headers into a dropdown for the user to select, after selecting it plots the signal and its spectrogram representation in the top row and a prediction probablity and feature importance plots at the bottom row. So far I’m getting only the top row to reflect the actual signal selected from the dropdown, the bottom row doesn’t seem refresh at all, specifically the prediction probability which I need to update depending the selected column. I’ve tried putting it in a conditional statement to check for a change in the dropdown selection but it still hasn’t solved the issue for me. I’d love to get some help from the community in resolving this issue, the code snippet is pasted below. Thanks in advance.
with open('model.pkl', 'rb') as model:
loaded_model = pickle.load(model)
with open('encoder.pkl', 'rb') as encoder:
loaded_encoder = pickle.load(encoder)
uploaded_file = st.file_uploader("Upload file:", type = "csv")
if uploaded_file is not None:
df = pd.read_csv(uploaded_file, index_col = 'Time,ms')
options = df.columns.tolist()
selected_column = st.selectbox("Select Signal", options, key = "signal_select")
if selected_column:
sigplot, spectrogram = st.columns([1, 1])
with sigplot:
plot_signal(selected_column)
with spectrogram:
plot_spectrogram(selected_column)
features = compute_features(selected_column)
# st.write(features)
prediction = loaded_model.predict(features)
prediction_probs = loaded_model.predict_proba(features)
# st.write(prediction, prediction_probs)
probs_plot, fi_plot = st.columns([1, 1])
with probs_plot:
fig, ax = plt.subplots()
st.write(prediction_probs.reshape(-1, 1))
probs_df = pd.DataFrame(prediction_probs.reshape(-1, 1), loaded_encoder.classes_)
probs_df.columns = ['value']
st.dataframe(probs_df)
ax.barh(probs_df.index, probs_df['value'])
st.pyplot(fig)
with fi_plot:
fig, ax = plt.subplots()
ax.barh(loaded_model.model.estimator.feature_name_, loaded_model.model.estimator.feature_importances_)
st.pyplot(fig)
- Are you running your app locally or is it deployed? Yes