Spaces:
Runtime error
Runtime error
nisharg nargund
commited on
Commit
·
c98a826
1
Parent(s):
6368686
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,33 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
|
|
|
|
3 |
|
4 |
-
# Load the model
|
5 |
-
model = keras.models.load_model("
|
6 |
-
|
7 |
-
# Create a function to make predictions
|
8 |
-
def predict(image):
|
9 |
-
prediction = model.predict(image)
|
10 |
-
return prediction
|
11 |
|
12 |
# Create a Streamlit app
|
13 |
-
st.title("
|
14 |
|
15 |
# Upload an image
|
16 |
-
image = st.file_uploader("Upload an image of a
|
17 |
|
18 |
-
#
|
19 |
if image is not None:
|
20 |
-
image =
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import tensorflow as tf
|
3 |
+
from PIL import Image
|
4 |
+
import numpy as np
|
5 |
|
6 |
+
# Load the TensorFlow model from the .h5 file
|
7 |
+
model = tf.keras.models.load_model("model.h5")
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
# Create a Streamlit app
|
10 |
+
st.title("Brain Tumor Detection")
|
11 |
|
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 |
+
# Button to make predictions
|
16 |
if image is not None:
|
17 |
+
image = Image.open(image)
|
18 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
19 |
+
|
20 |
+
# Preprocess the image
|
21 |
+
image = image.resize((224, 224)) # Adjust the size according to your model's input requirements
|
22 |
+
image = np.array(image)
|
23 |
+
image = image / 255.0 # Normalize the image to [0, 1]
|
24 |
+
image = np.expand_dims(image, axis=0) # Add batch dimension
|
25 |
+
|
26 |
+
# Make predictions
|
27 |
+
prediction = model.predict(image)
|
28 |
|
29 |
+
# Display prediction results
|
30 |
+
if prediction > 0.5:
|
31 |
+
st.write("Prediction: Tumor detected")
|
32 |
+
else:
|
33 |
+
st.write("Prediction: No tumor detected")
|