Simple Data Science Web App in Python using streamlit

Introduction

pip install streamlit
import pandas as pd
import numpy as np
import streamlit as st
from sklearn.ensemble import RandomForestClassifier
import pickle
st.write("""
# Simple Glass Identification Prediction App
This app predicts the **Type of Glass** type !
""")
st.sidebar.header('User Input Parameters')
st.write("""
# Simple Glass Identification Prediction App
This app predicts the **Type of Glass** type !
""")
st.sidebar.header('User Input Parameters')
columns = ['Id','RI','Na','Mg','Ai','Si','K','Ca','Ba','Fe','Label']
def user_input_features():
RI = st.sidebar.slider('Refractive Index',1.51,1.53,1.51)
Na = st.sidebar.slider('Sodium',2.0,4.4,3.4)
Mg = st.sidebar.slider('Magnesium',10.0,17.6,10.730)
Ai = st.sidebar.slider('Aluminium',2.0,4.9,2.115000)
Si = st.sidebar.slider('Sillicon',72.0,75.0,72.280)
K = st.sidebar.slider('Potassium',0.12,6.2,0.122500)
Ca = st.sidebar.slider('Calcium',8.24,16.19,8.24)
Ba = st.sidebar.slider('Barium',0.0,3.15,0.0)
Fe = st.sidebar.slider('Iron',0.0,0.51,0.2)
data = {'RI': RI,
'Na': Na,
'Mg':Mg,
'Ai':Ai,
'Si':Si,
'K':K,
'Ca':Ca,
'Ba':Ba,
'Fe':Fe
}
features = pd.DataFrame(data,index=[0])
return features
df = user_input_features()
st.subheader('User Input Parameters')
st.write(df)
test = df.copy()#load the model
filename = 'rf.pkl'
loaded_model = pickle.load(open(filename, 'rb'))
prediction = loaded_model.predict(test)
prediction_proba = loaded_model.predict_proba(test)
st.subheader('Class Labels and their corresponding index number')label_name = np.array(['building_windows_float_processed',
'building_windows_non_float_processed','vehicle_windows_float_',
'vehicle_windows_non_float_processed','containers',
'tableware','headlamps'])
st.write(label_name)
# labels -dictionarynames ={1:'building_windows_float_processed',
2: 'building_windows_non_float_processed',
3: 'vehicle_windows_float_processed',
4: 'vehicle_windows_non_float_processed',
5:'containers',
6: 'tableware',
7:'headlamps'}
st.subheader('Prediction')st.write(names[prediction[0]])st.subheader('Prediction Probability')
st.write(prediction_proba)
streamlit run Glass_Webapp.py
Snapshot of Streamlit Webapp

Machine Learning and Deep Learning enthusiast