demo-app / app.py
nisharg nargund
Update app.py
f8d3988
raw
history blame
1.06 kB
!pip install tensorflow
import streamlit as st
import tensorflow as tf
from PIL import Image
import numpy as np
import keras
# Load the TensorFlow model from the .h5 file
model = tf.keras.models.load_model("model.h5")
# Create a Streamlit app
st.title("Brain Tumor Detection")
# Upload an image
image = st.file_uploader("Upload an MRI image of a brain with a tumor", type=["jpg", "jpeg", "png"])
# Button to make predictions
if image is not None:
image = Image.open(image)
st.image(image, caption="Uploaded Image", use_column_width=True)
# Preprocess the image
image = image.resize((224, 224)) # Adjust the size according to your model's input requirements
image = np.array(image)
image = image / 255.0 # Normalize the image to [0, 1]
image = np.expand_dims(image, axis=0) # Add batch dimension
# Make predictions
prediction = model.predict(image)
# Display prediction results
if prediction > 0.5:
st.write("Prediction: Tumor detected")
else:
st.write("Prediction: No tumor detected")