Spaces:
Sleeping
Sleeping
File size: 5,692 Bytes
a7288b8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
import streamlit as st
import pandas as pd
import pickle
st.set_page_config(
page_title=" :mushroom: Mushroom App",
page_icon="🍄",
layout="wide",
initial_sidebar_state="expanded"
)
def user_input_features():
cap_diameter = st.sidebar.slider('Cap Diameter',
min_value=0.0,
max_value=2000.0,
value = 1000.0,
step=1.0,
)
cap_shape = st.sidebar.selectbox('Cap Shape',
options=('bell',
'conical',
'convex',
'flat',
'sunken',
'spherical',
'other')
)
gill_attachment = st.sidebar.selectbox('Gill Attachment',
options=('adnate',
'adnexed',
'decurrent',
'free',
'sinuate',
'pores',
'none')
)
gill_color = st.sidebar.selectbox('Gill Color',
options=('brown',
'buff',
'gray',
'green',
'pink',
'purple',
'red',
'white',
'yellow',
'blue',
'orange',
'black')
)
stem_height = st.sidebar.slider('Stem Height',
min_value=0.0,
max_value=4.0,
value=2.0,
step=0.1,
)
stem_width = st.sidebar.slider('Stem Width',
min_value=0.0,
max_value=4000.0,
value=2000.0,
step=1.0,
)
stem_color = st.sidebar.selectbox('Stem Color',
options=('brown',
'buff',
'gray',
'green',
'pink',
'purple',
'red',
'white',
'yellow',
'blue',
'orange',
'black')
)
season = st.sidebar.selectbox('Season',
options=('spring',
'summer',
'autumn',
'winter')
)
def get_color(color_name):
color_dict = {
'brown': 0,
'buff': 1,
'gray': 2,
'green': 3,
'pink': 4,
'purple': 5,
'red': 6,
'white': 7,
'yellow': 8,
'blue': 9,
'orange': 10,
'black': 11
}
return color_dict.get(color_name.lower(), "not found")
def get_cap_shape(cap_shape):
shape_dict = {
'bell': 0,
'conical': 1,
'convex': 2,
'flat': 3,
'sunken': 4,
'spherical': 5,
'other': 6
}
return shape_dict.get(cap_shape.lower(), "not found")
def get_gill_attachment(gill_attachment):
gill_attachment_dict = {
'adnate': 0,
'adnexed': 1,
'decurrent': 2,
'free': 3,
'sinuate': 4,
'pores': 5,
'none': 6
}
return gill_attachment_dict.get(gill_attachment.lower(), "not found")
def get_season(season):
season_dict = {
'spring': 0,
'summer': 1,
'autumn': 2,
'winter': 3
}
return season_dict.get(season.lower(), "not found")
data = {'cap-diameter': cap_diameter,
'cap-shape': get_cap_shape(cap_shape),
'gill-attachment': get_gill_attachment(gill_attachment),
'gill-color': get_color(gill_color),
'stem-height': stem_height,
'stem-width': stem_width,
'stem-color': get_color(stem_color),
'season': get_season(season)
}
features = pd.DataFrame(data, index=[0])
return features
#@st.cache_data()
def get_model():
model = pickle.load(open("models/rfc_model.pkl", "rb"))
return model
def make_prediction(data):
model = get_model()
return model.predict(data)
def main():
st.write("""# :mushroom: Mushroom App""")
st.sidebar.image("img/dataset-cover.jpg")
user_data = user_input_features()
if 'btn_predict' not in st.session_state:
st.session_state['btn_predict'] = False
st.session_state['btn_predict'] = st.button("Predict")
if st.session_state['btn_predict'] == True:
if make_prediction(user_data) == 1:
st.error("# Result: Poisonous :skull_and_crossbones: ")
else:
st.success("# Result: Edible :mushroom: ")
main() |