File size: 1,120 Bytes
d23ba8f
 
 
 
 
1f9592b
d23ba8f
 
 
 
 
 
 
 
1f9592b
362d662
9b6628a
362d662
9b6628a
362d662
1f9592b
362d662
 
9b6628a
 
362d662
 
 
 
 
 
 
1f9592b
362d662
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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")