import streamlit as st import numpy as np from PIL import Image from tensorflow.keras.models import load_model # Load the trained VGG16 model once @st.cache_resource def load_vgg_model(): return load_model("brain_tumor_vgg16_model.keras") # Streamlit UI st.title("Brain Tumor MRI Classification App") st.write("Upload a brain MRI scan to check if it contains a tumor.") # Load the model model = load_vgg_model() uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"]) if uploaded_file is not None: # Preprocess and predict image = Image.open(uploaded_file).convert("RGB") st.image(image, caption='Uploaded MRI Scan', use_column_width=True) img_size = 150 img_array = np.array(image.resize((img_size, img_size))) img_array = np.expand_dims(img_array, axis=0) img_array = img_array / 255.0 prediction = model.predict(img_array) class_predicted = (prediction > 0.5).astype("int32")[0][0] # Display result if class_predicted == 1: st.error("Prediction: Tumor Detected") else: st.success("Prediction: No Tumor Detected")