Spaces:
Runtime error
Runtime error
| # 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 | |