File size: 1,103 Bytes
ee9c3a8
247a01c
f8d3988
c98a826
 
16ea20c
 
c98a826
16ea20c
 
c98a826
16ea20c
ee9c3a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Import necessary libraries
import streamlit as st
import tensorflow as tf
from PIL import Image
import numpy as np

# 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"])

# Check if TensorFlow is available
if 'tensorflow' not in sys.modules:
    st.warning("TensorFlow is not available in this environment. Please ensure that you have the correct environment activated.")

else:
    # Load the TensorFlow model from the .h5 file
    model = tf.keras.models.load_model("model.h5")

    # 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