TroglodyteDerivations
commited on
Commit
•
7d1ce2b
1
Parent(s):
49a88f8
Updated line 7 with: # Disable the PyplotGlobalUseWarning st.set_option('deprecation.showPyplotGlobalUse', False) | Updated lines 34-45 with: display_images_and_predictions modifications
Browse files
app.py
CHANGED
@@ -4,6 +4,9 @@ from tensorflow.keras.models import load_model
|
|
4 |
from tensorflow.keras.preprocessing import image
|
5 |
import matplotlib.pyplot as plt
|
6 |
|
|
|
|
|
|
|
7 |
# Load the model
|
8 |
model = load_model('brain_tumor_model.keras')
|
9 |
|
@@ -30,16 +33,16 @@ def load_and_preprocess_image(image_path, image_shape=(168, 168)):
|
|
30 |
|
31 |
# Function to display a row of images with predictions
|
32 |
def display_images_and_predictions(image_paths, predictions, true_labels, figsize=(20, 5)):
|
33 |
-
plt.
|
34 |
for i, (image_path, prediction, true_label) in enumerate(zip(image_paths, predictions, true_labels)):
|
35 |
-
ax =
|
36 |
img_array = load_and_preprocess_image(image_path)
|
37 |
img_array = np.squeeze(img_array)
|
38 |
-
|
39 |
title_color = 'green' if prediction == true_label else 'red'
|
40 |
-
|
41 |
-
|
42 |
-
st.pyplot()
|
43 |
|
44 |
|
45 |
|
|
|
4 |
from tensorflow.keras.preprocessing import image
|
5 |
import matplotlib.pyplot as plt
|
6 |
|
7 |
+
# Disable the PyplotGlobalUseWarning
|
8 |
+
st.set_option('deprecation.showPyplotGlobalUse', False)
|
9 |
+
|
10 |
# Load the model
|
11 |
model = load_model('brain_tumor_model.keras')
|
12 |
|
|
|
33 |
|
34 |
# Function to display a row of images with predictions
|
35 |
def display_images_and_predictions(image_paths, predictions, true_labels, figsize=(20, 5)):
|
36 |
+
fig, axes = plt.subplots(1, len(image_paths), figsize=figsize)
|
37 |
for i, (image_path, prediction, true_label) in enumerate(zip(image_paths, predictions, true_labels)):
|
38 |
+
ax = axes[i]
|
39 |
img_array = load_and_preprocess_image(image_path)
|
40 |
img_array = np.squeeze(img_array)
|
41 |
+
ax.imshow(img_array, cmap='gray')
|
42 |
title_color = 'green' if prediction == true_label else 'red'
|
43 |
+
ax.set_title(f'True Label: {true_label}\nPred: {prediction}', color=title_color)
|
44 |
+
ax.axis('off')
|
45 |
+
st.pyplot(fig)
|
46 |
|
47 |
|
48 |
|