Spaces:
Runtime error
Runtime error
nisharg nargund
commited on
Commit
·
ee9c3a8
1
Parent(s):
f8d3988
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,10 @@
|
|
1 |
!pip install tensorflow
|
|
|
|
|
2 |
import streamlit as st
|
3 |
import tensorflow as tf
|
4 |
from PIL import Image
|
5 |
import numpy as np
|
6 |
-
import keras
|
7 |
-
|
8 |
-
# Load the TensorFlow model from the .h5 file
|
9 |
-
model = tf.keras.models.load_model("model.h5")
|
10 |
|
11 |
# Create a Streamlit app
|
12 |
st.title("Brain Tumor Detection")
|
@@ -14,22 +12,23 @@ st.title("Brain Tumor Detection")
|
|
14 |
# Upload an image
|
15 |
image = st.file_uploader("Upload an MRI image of a brain with a tumor", type=["jpg", "jpeg", "png"])
|
16 |
|
17 |
-
#
|
18 |
-
if
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
#
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
1 |
!pip install tensorflow
|
2 |
+
|
3 |
+
# Import necessary libraries
|
4 |
import streamlit as st
|
5 |
import tensorflow as tf
|
6 |
from PIL import Image
|
7 |
import numpy as np
|
|
|
|
|
|
|
|
|
8 |
|
9 |
# Create a Streamlit app
|
10 |
st.title("Brain Tumor Detection")
|
|
|
12 |
# Upload an image
|
13 |
image = st.file_uploader("Upload an MRI image of a brain with a tumor", type=["jpg", "jpeg", "png"])
|
14 |
|
15 |
+
# Check if TensorFlow is available
|
16 |
+
if 'tensorflow' not in sys.modules:
|
17 |
+
st.warning("TensorFlow is not available in this environment. Please ensure that you have the correct environment activated.")
|
18 |
+
|
19 |
+
else:
|
20 |
+
# Load the TensorFlow model from the .h5 file
|
21 |
+
model = tf.keras.models.load_model("model.h5")
|
22 |
+
|
23 |
+
# Button to make predictions
|
24 |
+
if image is not None:
|
25 |
+
image = Image.open(image)
|
26 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
27 |
+
|
28 |
+
# Preprocess the image
|
29 |
+
image = image.resize((224, 224)) # Adjust the size according to your model's input requirements
|
30 |
+
image = np.array(image)
|
31 |
+
image = image / 255.0 # Normalize the image to [0, 1]
|
32 |
+
image = np.expand_dims(image, axis=0) # Add batch dimension
|
33 |
+
|
34 |
+
# Make predictions
|