import streamlit as st from PIL import Image import numpy as np from tensorflow.keras.models import load_model from tensorflow.keras.preprocessing import image from tensorflow.keras.applications.vgg16 import preprocess_input # Load your trained model model = load_model('BT(Deploy).h5') # Replace with your model's path # Set Streamlit page config for a better layout st.set_page_config(page_title="Brain Tumor Detection", page_icon="🧠", layout="centered") # Add a title and description st.title("Brain Tumor Detection 🧠") st.markdown(""" Upload a brain MRI scan to detect whether it contains a brain tumor or not. Our model uses advanced deep learning to analyze your scan and provide a prediction. """) # File uploader with custom styling uploaded_file = st.file_uploader("Upload a Brain MRI Scan", type=["jpg", "png", "jpeg"], label_visibility="collapsed") # Function to preprocess the image def preprocess_image(img): img = img.resize((224, 224)) # Resize to 224x224 img_array = np.array(img) # Convert image to numpy array img_array = np.expand_dims(img_array, axis=0) # Add batch dimension img_array = preprocess_input(img_array) # Preprocess image for VGG16 return img_array if uploaded_file is not None: # Display the uploaded image img = Image.open(uploaded_file) st.image(img, caption="Uploaded MRI Scan", use_container_width=True) # Preprocess and predict try: processed_image = preprocess_image(img) st.write("Image successfully preprocessed!") # Model prediction prediction = model.predict(processed_image) # Display prediction result with styling st.subheader("Prediction Results") if prediction[0][0] > 0.5: st.markdown('

⚠️ Brain Tumor Detected

', unsafe_allow_html=True) else: st.markdown('

✅ No Brain Tumor Detected

', unsafe_allow_html=True) except Exception as e: st.error(f"Error in preprocessing or prediction: {e}") # Add footer and additional information st.markdown(""" --- **Developed with 💙 by [Abhinav]** This project is aimed at helping doctors detect brain tumors from MRI scans using deep learning models. """) # Custom styling for Streamlit components st.markdown(""" """, unsafe_allow_html=True)