File size: 1,035 Bytes
16ea20c
c98a826
 
 
022bcdd
16ea20c
c98a826
 
16ea20c
 
c98a826
16ea20c
 
c98a826
16ea20c
c98a826
16ea20c
c98a826
 
 
 
 
 
 
 
 
 
 
16ea20c
c98a826
 
 
 
 
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
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")