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