Skip to content

Commit 4dfcc67

Browse files
committed
finshed building out streamlit app
1 parent 8df1223 commit 4dfcc67

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

Streamlit/app.py

+18-7
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616

1717
_ = """
1818
All comments will be assigned to the underscore variable so they dont get rendered in streamlit
19-
as mention in this discussion form:
19+
as mention in this discussion fourm:
2020
https://discuss.streamlit.io/t/any-way-to-prevent-commented-out-code-via-triple-quotes-to-be-displayed-in-streamlit/8821/6
2121
2222
This code takes heavy influece from a previous project.
2323
https://github.com/DerikVo/NN_hackathon
2424
25-
There were many changes to the code to get it to work with this data set,
25+
There were many changes to the code to get it to work with this data set as well as provide additional features,
2626
but the general structure remains the same
2727
"""
2828

@@ -33,8 +33,14 @@ def load_model_stream():
3333
path = "../Models/CNN_base.h5"
3434
model = load_model(path)
3535
return model
36-
37-
# function to preprocess an image and get a prediction from the model
36+
_ = """
37+
function to preprocess an image and get a prediction from the model
38+
code was copied into chatGPT3 with the prompt "how do I modify this code to covert a single image to make predictions on what class it belongs to.
39+
The image and classes are in greyscale" was provided with this code.
40+
According to stackoverflow this method is used for greyscaling an image.
41+
My interptation is by greyscaling our image we ensure it matchs the training data which gets read in as a greyscale image:
42+
https://stackoverflow.com/questions/52307290/what-is-the-difference-between-images-in-p-and-l-mode-in-pil
43+
"""
3844
def get_prediction(model, image):
3945
open_image = Image.open(image)
4046
resized_image = open_image.resize((256, 256))
@@ -43,6 +49,7 @@ def get_prediction(model, image):
4349
predicted_prob = model.predict(img)[0]
4450
classes = ['glioma', 'meningioma', 'notumor', 'pituitary']
4551
probabilities = dict(zip(classes, predicted_prob))
52+
#referenced https://www.freecodecamp.org/news/sort-dictionary-by-value-in-python/
4653
sorted_probabilities = sorted(probabilities.items(), key=lambda x: x[1], reverse=True)
4754
return sorted_probabilities
4855
def upload_mode():
@@ -100,8 +107,11 @@ def model_Evaluation(path):
100107
return data
101108
_ ='''
102109
This code utilized the streamlit documentation to implement columns
103-
and displaying images. In the future I want users to be able to upload their model and have it
104-
automatically be evaluated by the app.
110+
and displaying images.
111+
112+
In the future I want users to be able to upload their model and have it
113+
automatically be evaluated by the app. However, currently when I create a function to upload the model, I am unable to pass it into the model evaluation function.
114+
The model being passed isnt being interpreted as a h5 file.
105115
106116
The links are as folows:
107117
https://docs.streamlit.io/library/api-reference/layout/st.columns
@@ -115,7 +125,7 @@ def model_Evaluation(path):
115125
reg_path = ('../Models/CNN_regularization.h5')
116126
reg_data = model_Evaluation(path)
117127
st.write("CNN base Metrics:\n")
118-
128+
#create a column for metric scores and display the confusion matrix for the neural network without regularization
119129
col1, col2 = st.columns(2)
120130
with col1:
121131
for metric_name, metric_value in data.items():
@@ -126,6 +136,7 @@ def model_Evaluation(path):
126136
st.write("")
127137
st.write("")
128138
st.write("\n CNN regularization Metrics:")
139+
#create a column for metric scores and display the confusion matrix for the neural network with regularization
129140
col3, col4 = st.columns(2)
130141
with col3:
131142
for metric_name, metric_value in reg_data.items():

0 commit comments

Comments
 (0)