Myapp.py not displaying in browser

Hi all,

I’m an absolute beginner at streamlit and quite new python/machine learning in general. I am trying to use streamlit to make a small app that takes inputs from a user and feeds them into an ML model and then displays a prediction.

I have adapted code that I found in a tutorial here:

My own code is as follows:
%%writefile myapp.py

import pickle
import streamlit as st

pickle_in = open(‘classifier.pkl’, ‘rb’)
classifier = pickle.load(pickle_in)

@st.cache()

def prediction(d2, ex1, gx3, e1):

if d2 == "Grade 0":
    d2 = 0
elif d2 == "Grade 1":
    d2 = 1
elif d2 == "Grade 2":
    d2 = 2
elif d2 == "Grade 3":
    d2 = 3
elif d2 == "Grade 4":
    d2 = 4
elif d2 == "Grade 5":
    d2 = 5
elif d2 == "Grade 6":
    d2 = 6
else: d2 = 0 
    
    
if ex1 == "Grade 0":
    ex1 = 0
elif ex1 == "Grade 1":
    ex1 = 1
elif ex1 == "Grade 2":
    ex1 = 2
elif ex1 == "Grade 3":
    ex1 = 3
elif ex1 == "Grade 4":
    ex1 = 4
elif ex1 == "Grade 5":
    ex1 = 5
elif ex1 == "Grade 6":
    ex1 = 6
else: ex1 = 0 


if gx3 == "Grade 0":
    gx3 = 0
elif gx3 == "Grade 1":
    gx3 = 1
elif gx3 == "Grade 2":
    gx3 = 2
elif gx3 == "Grade 3":
    gx3 = 3
elif gx3 == "Grade 4":
    gx3 = 4
elif gx3 == "Grade 5":
    gx3 = 5
elif gx3 == "Grade 6":
    gx3 = 6
else: gx3 = 0 ## mode value for gx3

        
if e1 == "Grade 0":
    e1 = 0
elif e1 == "Grade 1":
    e1 = 1
elif e1 == "Grade 2":
    e1 = 2
elif e1 == "Grade 3":
    e1 = 3
elif e1 == "Grade 4":
    e1 = 4
elif e1 == "Grade 5":
    e1 = 5
elif e1 == "Grade 6":
    e1 = 6
else: e1 = 0 ## mode value for e1


prediction = classifier.predict( 
    [[d2, ex1, gx3, e1]])
 
if prediction == 0:
    pred = 'Grade 0'
elif prediction == 1:
    pred = 'Grade 1'
elif prediction == 2:
    pred = 'Grade 2'
elif prediction == 3:
    pred = 'Grade 3'
elif prediction == 4:
    pred = 'Grade 4'
elif prediction == 5:
    pred = 'Grade 5'
else: pred = 'Grade 6'
return pred
  
def main():       
    html_temp = """ 
    <div style ="background-color:yellow;padding:13px"> 
    <h1 style ="color:black;text-align:center;">Streamlit Loan Prediction ML App</h1> 
    </div> 
    """
  
st.markdown(html_temp, unsafe_allow_html = True) 
  
d2 = st.selectbox('d2 allergen result',("Grade 0","Grade 1","Grade 2","Grade 3","Grade 4","Grade 5","Grade 6", "Unknown"))
ex1 = st.selectbox('ex1 allergen result',("Grade 0","Grade 1","Grade 2","Grade 3","Grade 4","Grade 5","Grade 6", "Unknown"))
gx3 = st.selectbox('gx3 allergen result',("Grade 0","Grade 1","Grade 2","Grade 3","Grade 4","Grade 5","Grade 6", "Unknown"))
e1 = st.selectbox('e1 allergen result',("Grade 0","Grade 1","Grade 2","Grade 3","Grade 4","Grade 5","Grade 6", "Unknown"))
result =""
  

if st.button("Predict"): 
    result = prediction(d2, ex1, gx3, e1) 
    st.success('Predicted grade for d1: {}'.format(result))
    print(pred)
 
if __name__=='__main__': 
    main()

After running the command ‘streamlit run myapp.py’ in an anaconda environment my browser just displays an empty window. Can anybody help me here?

Thanks

Edit: Removed some formatting from my jupyter notebook

Hi all, just updating to say I see that my error was an incorrect indentation.

Thanks!