|
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 |
|
|
|
|
|
model = load_model('BT(Deploy).h5') |
|
|
|
|
|
st.set_page_config(page_title="Brain Tumor Detection", page_icon="π§ ", layout="centered") |
|
|
|
|
|
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. |
|
""") |
|
|
|
|
|
uploaded_file = st.file_uploader("Upload a Brain MRI Scan", type=["jpg", "png", "jpeg"], label_visibility="collapsed") |
|
|
|
|
|
|
|
def preprocess_image(img): |
|
img = img.resize((224, 224)) |
|
img_array = np.array(img) |
|
img_array = np.expand_dims(img_array, axis=0) |
|
img_array = preprocess_input(img_array) |
|
return img_array |
|
|
|
|
|
if uploaded_file is not None: |
|
|
|
img = Image.open(uploaded_file) |
|
st.image(img, caption="Uploaded MRI Scan", use_container_width=True) |
|
|
|
|
|
try: |
|
processed_image = preprocess_image(img) |
|
st.write("Image successfully preprocessed!") |
|
|
|
|
|
prediction = model.predict(processed_image) |
|
|
|
|
|
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}") |
|
|
|
|
|
st.markdown(""" |
|
--- |
|
**Developed with π by [Abhinav]** |
|
This project is aimed at helping doctors detect brain tumors from MRI scans using deep learning models. |
|
""") |
|
|
|
|
|
st.markdown(""" |
|
<style> |
|
.css-1v0mbdj { |
|
font-size: 20px; |
|
font-weight: bold; |
|
} |
|
.css-5wyi5j { |
|
background-color: #f0f0f5; |
|
} |
|
</style> |
|
""", unsafe_allow_html=True) |
|
|