I created an app using Streamlit. I am trying to display the result but it is displayed only in the terminal and the interface shows NONE. there are no errors shown, all works perfect. Here is my code:
import pickle
import numpy as np
import streamlit as st
loaded_model=pickle.load(open("C:/trained_model.sav",'rb'))
def prediction(input_data):
input_data_numpy= np.asarray(input_data)
input_data_reshape=input_data_numpy.reshape(1,-1)
prediction=loaded_model.predict(input_data_reshape)
print(prediction)
def main():
st.title("Predict quantity")
strain = st.radio("strain:",("cereal","sugar","salt"))
plNr=st.slider('Number of plants:', 10, 2340, 25)
result = ""
if strain == "cereal":
strain = 1
elif strain == "sugar":
strain = 2
else:
strain = 3
if st.button("result"):
result= prediction([strain,plNr])
st.success(result)
if __name__ =="__main__":
main()
(py108) C:\Users\s>streamlit run "C:\Users\prediction.py" You can now view your Streamlit app in your browser.
Local URL: http://localhost:8501 Network URL:
[[0.42784861]]
My terminal shows the result: [[0.42784861]] but the interface shows like this: Can anyone help me out please?
You didn't return anything from the prediction
function, hence the None
value.
I'd highly recommend you to use type hints, so that these errors are caught by the IDE.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.