Upload 3 files
Browse filesFinal trained model v1.
- .gitattributes +1 -0
- app.py +104 -0
- brain_tumor_model.keras +3 -0
- requirements.txt +165 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
brain_tumor_model.keras filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
from tensorflow.keras.models import load_model
|
| 4 |
+
import numpy as np
|
| 5 |
+
from PIL import Image
|
| 6 |
+
|
| 7 |
+
# --- 1. Configuration (Constants) ---
|
| 8 |
+
MODEL_PATH = 'brain_tumor_model.keras'
|
| 9 |
+
IMAGE_SIZE = (224, 224)
|
| 10 |
+
# Aapki training ke hisaab se classes ki list. Order maintain rakhna zaroori hai.
|
| 11 |
+
CLASS_NAMES = ['glioma_tumor', 'meningioma_tumor', 'no_tumor', 'pituitary_tumor']
|
| 12 |
+
|
| 13 |
+
# --- 2. Model Loading ---
|
| 14 |
+
# Streamlit app ki performance badhane ke liye model ko cache mein load karte hain
|
| 15 |
+
@st.cache_resource
|
| 16 |
+
def load_trained_model():
|
| 17 |
+
"""Trained model ko load karta hai."""
|
| 18 |
+
try:
|
| 19 |
+
# Load the saved model (using the .keras file)
|
| 20 |
+
model = load_model(MODEL_PATH)
|
| 21 |
+
return model
|
| 22 |
+
except Exception as e:
|
| 23 |
+
st.error(f"Error loading model: {e}")
|
| 24 |
+
return None
|
| 25 |
+
|
| 26 |
+
model = load_trained_model()
|
| 27 |
+
|
| 28 |
+
# --- 3. Prediction Function ---
|
| 29 |
+
def predict_image(image_file, model):
|
| 30 |
+
"""Uploaded image par prediction karta hai."""
|
| 31 |
+
if model is None:
|
| 32 |
+
return "Model Load Failed", 0.0
|
| 33 |
+
|
| 34 |
+
# PIL image ko array mein convert karein
|
| 35 |
+
img = Image.open(image_file).convert("RGB")
|
| 36 |
+
# Image ko model ke input size mein resize karein (224x224)
|
| 37 |
+
img = img.resize(IMAGE_SIZE)
|
| 38 |
+
img_array = np.array(img)
|
| 39 |
+
|
| 40 |
+
# Batch dimension add karein: (224, 224, 3) se (1, 224, 224, 3)
|
| 41 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 42 |
+
|
| 43 |
+
# Normalization (jaisa training mein kiya tha: 1./255)
|
| 44 |
+
img_array = img_array / 255.0
|
| 45 |
+
|
| 46 |
+
# Prediction karein
|
| 47 |
+
predictions = model.predict(img_array)
|
| 48 |
+
|
| 49 |
+
# Highest probability index aur score nikalien
|
| 50 |
+
predicted_index = np.argmax(predictions, axis=1)[0]
|
| 51 |
+
confidence_score = np.max(predictions) * 100
|
| 52 |
+
|
| 53 |
+
predicted_class = CLASS_NAMES[predicted_index]
|
| 54 |
+
|
| 55 |
+
return predicted_class, confidence_score
|
| 56 |
+
|
| 57 |
+
# --- 4. Streamlit UI ---
|
| 58 |
+
|
| 59 |
+
st.set_page_config(page_title="Brain Tumor Detection", layout="wide")
|
| 60 |
+
|
| 61 |
+
# a) Page Title
|
| 62 |
+
st.title("🧠 Brain Tumor Detection System (AI Powered)")
|
| 63 |
+
st.write("Upload an MRI image below to classify it as one of the tumor types or no tumor.")
|
| 64 |
+
st.markdown("---")
|
| 65 |
+
|
| 66 |
+
col1, col2 = st.columns(2)
|
| 67 |
+
|
| 68 |
+
with col1:
|
| 69 |
+
# b) Image Upload Section
|
| 70 |
+
uploaded_file = st.file_uploader("Upload MRI Image:", type=["jpg", "jpeg", "png"])
|
| 71 |
+
|
| 72 |
+
if uploaded_file is not None:
|
| 73 |
+
# Image Preview
|
| 74 |
+
st.image(uploaded_file, caption="Uploaded MRI Image", use_column_width=True)
|
| 75 |
+
st.markdown("---")
|
| 76 |
+
|
| 77 |
+
# c) Prediction Button
|
| 78 |
+
if st.button("Detect Tumor"):
|
| 79 |
+
st.spinner("Analyzing image and detecting tumor...")
|
| 80 |
+
|
| 81 |
+
# Prediction
|
| 82 |
+
predicted_class, confidence_score = predict_image(uploaded_file, model)
|
| 83 |
+
|
| 84 |
+
# d) Output Section
|
| 85 |
+
|
| 86 |
+
# Simplified classification for the app display (Tumor / No Tumor)
|
| 87 |
+
if predicted_class == 'no_tumor':
|
| 88 |
+
result_label = f"🟢 **Prediction: No Tumor**"
|
| 89 |
+
else:
|
| 90 |
+
result_label = f"🔴 **Prediction: Tumor ({predicted_class.replace('_', ' ').title()})**"
|
| 91 |
+
|
| 92 |
+
st.success("✅ Analysis Complete")
|
| 93 |
+
st.subheader(result_label)
|
| 94 |
+
st.metric(label="Confidence Score", value=f"{confidence_score:.2f}%")
|
| 95 |
+
|
| 96 |
+
st.write("---")
|
| 97 |
+
|
| 98 |
+
with col2:
|
| 99 |
+
st.header("Results and Interpretation")
|
| 100 |
+
st.info("The system uses Transfer Learning (VGG16) to classify the image into four categories: Glioma, Meningioma, Pituitary, or No Tumor.")
|
| 101 |
+
#
|
| 102 |
+
|
| 103 |
+
if uploaded_file is None:
|
| 104 |
+
st.warning("Please upload an image and click 'Detect Tumor' to see the results.")
|
brain_tumor_model.keras
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d20e5a0cf49890f3b06898737a2f0a84dc9febfe70a184da563c967d7846cbf5
|
| 3 |
+
size 136037810
|
requirements.txt
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
absl-py==2.3.1
|
| 2 |
+
aiohappyeyeballs==2.6.1
|
| 3 |
+
aiohttp==3.13.2
|
| 4 |
+
aiosignal==1.4.0
|
| 5 |
+
altair==6.0.0
|
| 6 |
+
annotated-types==0.7.0
|
| 7 |
+
anyio==4.12.0
|
| 8 |
+
astunparse==1.6.3
|
| 9 |
+
async-timeout==4.0.3
|
| 10 |
+
attrs==25.4.0
|
| 11 |
+
backoff==2.2.1
|
| 12 |
+
bcrypt==5.0.0
|
| 13 |
+
blinker==1.9.0
|
| 14 |
+
build==1.3.0
|
| 15 |
+
cachetools==6.2.2
|
| 16 |
+
certifi==2025.11.12
|
| 17 |
+
charset-normalizer==3.4.4
|
| 18 |
+
chromadb==1.3.6
|
| 19 |
+
click==8.3.1
|
| 20 |
+
colorama==0.4.6
|
| 21 |
+
coloredlogs==15.0.1
|
| 22 |
+
dataclasses-json==0.6.7
|
| 23 |
+
distro==1.9.0
|
| 24 |
+
durationpy==0.10
|
| 25 |
+
exceptiongroup==1.3.1
|
| 26 |
+
filelock==3.20.0
|
| 27 |
+
flatbuffers==25.9.23
|
| 28 |
+
frozenlist==1.8.0
|
| 29 |
+
fsspec==2025.12.0
|
| 30 |
+
gast==0.7.0
|
| 31 |
+
gitdb==4.0.12
|
| 32 |
+
GitPython==3.1.45
|
| 33 |
+
google-auth==2.43.0
|
| 34 |
+
google-pasta==0.2.0
|
| 35 |
+
googleapis-common-protos==1.72.0
|
| 36 |
+
greenlet==3.3.0
|
| 37 |
+
grpcio==1.76.0
|
| 38 |
+
h11==0.16.0
|
| 39 |
+
h5py==3.15.1
|
| 40 |
+
hf-xet==1.2.0
|
| 41 |
+
httpcore==1.0.9
|
| 42 |
+
httptools==0.7.1
|
| 43 |
+
httpx==0.28.1
|
| 44 |
+
httpx-sse==0.4.3
|
| 45 |
+
huggingface_hub==1.2.2
|
| 46 |
+
humanfriendly==10.0
|
| 47 |
+
idna==3.11
|
| 48 |
+
importlib_metadata==8.7.0
|
| 49 |
+
importlib_resources==6.5.2
|
| 50 |
+
Jinja2==3.1.6
|
| 51 |
+
jiter==0.12.0
|
| 52 |
+
jsonpatch==1.33
|
| 53 |
+
jsonpointer==3.0.0
|
| 54 |
+
jsonschema==4.25.1
|
| 55 |
+
jsonschema-specifications==2025.9.1
|
| 56 |
+
kagglehub==0.3.13
|
| 57 |
+
keras==3.12.0
|
| 58 |
+
kubernetes==34.1.0
|
| 59 |
+
langchain==1.1.3
|
| 60 |
+
langchain-classic==1.0.0
|
| 61 |
+
langchain-community==0.4.1
|
| 62 |
+
langchain-core==1.1.3
|
| 63 |
+
langchain-openai==1.1.1
|
| 64 |
+
langchain-text-splitters==1.0.0
|
| 65 |
+
langgraph==1.0.4
|
| 66 |
+
langgraph-checkpoint==3.0.1
|
| 67 |
+
langgraph-prebuilt==1.0.5
|
| 68 |
+
langgraph-sdk==0.2.15
|
| 69 |
+
langsmith==0.4.59
|
| 70 |
+
libclang==18.1.1
|
| 71 |
+
Markdown==3.10
|
| 72 |
+
markdown-it-py==4.0.0
|
| 73 |
+
MarkupSafe==3.0.3
|
| 74 |
+
marshmallow==3.26.1
|
| 75 |
+
mdurl==0.1.2
|
| 76 |
+
ml_dtypes==0.5.4
|
| 77 |
+
mmh3==5.2.0
|
| 78 |
+
mpmath==1.3.0
|
| 79 |
+
multidict==6.7.0
|
| 80 |
+
mypy_extensions==1.1.0
|
| 81 |
+
namex==0.1.0
|
| 82 |
+
narwhals==2.13.0
|
| 83 |
+
numpy==2.2.6
|
| 84 |
+
oauthlib==3.3.1
|
| 85 |
+
onnxruntime==1.23.2
|
| 86 |
+
openai==2.9.0
|
| 87 |
+
opentelemetry-api==1.39.0
|
| 88 |
+
opentelemetry-exporter-otlp-proto-common==1.39.0
|
| 89 |
+
opentelemetry-exporter-otlp-proto-grpc==1.39.0
|
| 90 |
+
opentelemetry-proto==1.39.0
|
| 91 |
+
opentelemetry-sdk==1.39.0
|
| 92 |
+
opentelemetry-semantic-conventions==0.60b0
|
| 93 |
+
opt_einsum==3.4.0
|
| 94 |
+
optree==0.18.0
|
| 95 |
+
orjson==3.11.5
|
| 96 |
+
ormsgpack==1.12.0
|
| 97 |
+
overrides==7.7.0
|
| 98 |
+
packaging==25.0
|
| 99 |
+
pandas==2.3.3
|
| 100 |
+
pillow==12.0.0
|
| 101 |
+
posthog==5.4.0
|
| 102 |
+
propcache==0.4.1
|
| 103 |
+
protobuf==6.33.2
|
| 104 |
+
pyarrow==22.0.0
|
| 105 |
+
pyasn1==0.6.1
|
| 106 |
+
pyasn1_modules==0.4.2
|
| 107 |
+
pybase64==1.4.3
|
| 108 |
+
pydantic==2.12.5
|
| 109 |
+
pydantic-settings==2.12.0
|
| 110 |
+
pydantic_core==2.41.5
|
| 111 |
+
pydeck==0.9.1
|
| 112 |
+
Pygments==2.19.2
|
| 113 |
+
pypdf==6.4.1
|
| 114 |
+
PyPika==0.48.9
|
| 115 |
+
pyproject_hooks==1.2.0
|
| 116 |
+
pyreadline3==3.5.4
|
| 117 |
+
python-dateutil==2.9.0.post0
|
| 118 |
+
python-dotenv==1.2.1
|
| 119 |
+
pytz==2025.2
|
| 120 |
+
PyYAML==6.0.3
|
| 121 |
+
referencing==0.37.0
|
| 122 |
+
regex==2025.11.3
|
| 123 |
+
requests==2.32.5
|
| 124 |
+
requests-oauthlib==2.0.0
|
| 125 |
+
requests-toolbelt==1.0.0
|
| 126 |
+
rich==14.2.0
|
| 127 |
+
rpds-py==0.30.0
|
| 128 |
+
rsa==4.9.1
|
| 129 |
+
shellingham==1.5.4
|
| 130 |
+
six==1.17.0
|
| 131 |
+
smmap==5.0.2
|
| 132 |
+
sniffio==1.3.1
|
| 133 |
+
SQLAlchemy==2.0.45
|
| 134 |
+
streamlit==1.52.1
|
| 135 |
+
sympy==1.14.0
|
| 136 |
+
tenacity==9.1.2
|
| 137 |
+
tensorboard==2.20.0
|
| 138 |
+
tensorboard-data-server==0.7.2
|
| 139 |
+
tensorflow==2.20.0
|
| 140 |
+
termcolor==3.2.0
|
| 141 |
+
tiktoken==0.12.0
|
| 142 |
+
tokenizers==0.22.1
|
| 143 |
+
toml==0.10.2
|
| 144 |
+
tomli==2.3.0
|
| 145 |
+
tornado==6.5.3
|
| 146 |
+
tqdm==4.67.1
|
| 147 |
+
typer==0.20.0
|
| 148 |
+
typer-slim==0.20.0
|
| 149 |
+
typing-inspect==0.9.0
|
| 150 |
+
typing-inspection==0.4.2
|
| 151 |
+
typing_extensions==4.15.0
|
| 152 |
+
tzdata==2025.2
|
| 153 |
+
urllib3==2.3.0
|
| 154 |
+
uuid_utils==0.12.0
|
| 155 |
+
uvicorn==0.38.0
|
| 156 |
+
watchdog==6.0.0
|
| 157 |
+
watchfiles==1.1.1
|
| 158 |
+
websocket-client==1.9.0
|
| 159 |
+
websockets==15.0.1
|
| 160 |
+
Werkzeug==3.1.4
|
| 161 |
+
wrapt==2.0.1
|
| 162 |
+
xxhash==3.6.0
|
| 163 |
+
yarl==1.22.0
|
| 164 |
+
zipp==3.23.0
|
| 165 |
+
zstandard==0.25.0
|