File size: 2,603 Bytes
e5c9bc0 afa1dac e5c9bc0 2cc6376 e5c9bc0 |
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
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('<p style="font-size:18px;color:red;">β οΈ Brain Tumor Detected</p>', unsafe_allow_html=True)
else:
st.markdown('<p style="font-size:18px;color:green;">β
No Brain Tumor Detected</p>', 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("""
<style>
.css-1v0mbdj {
font-size: 20px;
font-weight: bold;
}
.css-5wyi5j {
background-color: #f0f0f5;
}
</style>
""", unsafe_allow_html=True)
|