saad1BM commited on
Commit
88c18bf
·
verified ·
1 Parent(s): fa6a722

Upload 3 files

Browse files

Final trained model v1

Files changed (4) hide show
  1. .gitattributes +1 -0
  2. app.py +133 -0
  3. brain_tumor_model.keras +3 -0
  4. 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,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import os
7
+ import requests
8
+
9
+
10
+ HF_REPO_ID = "saad1BM/brain-tumor-detection" # <-- CONFIRMED REPO ID
11
+ MODEL_FILENAME = "brain_tumor_model.keras"
12
+ MODEL_PATH = MODEL_FILENAME
13
+
14
+ IMAGE_SIZE = (224, 224)
15
+ CLASS_NAMES = ['glioma_tumor', 'meningioma_tumor', 'no_tumor', 'pituitary_tumor']
16
+
17
+
18
+ @st.cache_resource
19
+ def load_trained_model():
20
+ """Trained model ko Hugging Face se download aur load karta hai."""
21
+
22
+
23
+ MIN_SIZE = 100 * 1024 * 1024
24
+
25
+ try:
26
+ # Check karein ki model pehle se download hai ya nahi ya file corrupt/incomplete hai
27
+ if not os.path.exists(MODEL_PATH) or os.path.getsize(MODEL_PATH) < MIN_SIZE:
28
+ st.info(f"Downloading model from Hugging Face: {HF_REPO_ID}")
29
+
30
+
31
+ model_url = f"https://huggingface.co/{HF_REPO_ID}/resolve/main/{MODEL_FILENAME}"
32
+
33
+
34
+ r = requests.get(model_url, allow_redirects=True)
35
+
36
+
37
+ r.raise_for_status()
38
+
39
+
40
+ with open(MODEL_PATH, 'wb') as f:
41
+ f.write(r.content)
42
+ st.success("Model download successful!")
43
+
44
+
45
+ model = load_model(MODEL_PATH)
46
+ return model
47
+
48
+ except requests.exceptions.HTTPError as hf_err:
49
+ st.error(f"Error 404/401: Model not found on Hugging Face. Please check {HF_REPO_ID}/{MODEL_FILENAME}.")
50
+ return None
51
+ except Exception as e:
52
+ st.error(f"Final Keras Load Error: Model file may be incomplete or corrupted. ({e})")
53
+ return None
54
+
55
+ model = load_trained_model()
56
+
57
+
58
+
59
+ def predict_image(image_file, model):
60
+     """Uploaded image par prediction karta hai."""
61
+     if model is None:
62
+         return "Model Load Failed", 0.0
63
+
64
+  
65
+     img = Image.open(image_file).convert("RGB")
66
+    
67
+     img = img.resize(IMAGE_SIZE)
68
+     img_array = np.array(img)
69
+  
70
+     img_array = np.expand_dims(img_array, axis=0)
71
+     
72
+  
73
+     img_array = img_array / 255.0
74
+
75
+    
76
+     predictions = model.predict(img_array)
77
+     
78
+    
79
+     predicted_index = np.argmax(predictions, axis=1)[0]
80
+     confidence_score = np.max(predictions) * 100
81
+
82
+     predicted_class = CLASS_NAMES[predicted_index]
83
+     
84
+     return predicted_class, confidence_score
85
+
86
+
87
+
88
+ st.set_page_config(page_title="Brain Tumor Detection", layout="wide")
89
+
90
+
91
+ st.title("Brain Tumor Detection System (AI Powered)")
92
+ st.write("Upload an MRI image below to classify it as one of the tumor types or no tumor.")
93
+ st.markdown("---")
94
+
95
+ col1, col2 = st.columns(2)
96
+
97
+ with col1:
98
+    
99
+     uploaded_file = st.file_uploader("Upload MRI Image:", type=["jpg", "jpeg", "png"])
100
+     
101
+     if uploaded_file is not None:
102
+        
103
+         st.image(uploaded_file, caption="Uploaded MRI Image", use_column_width=True)
104
+         st.markdown("---")
105
+
106
+        
107
+         if st.button("Detect Tumor"):
108
+             st.spinner("Analyzing image and detecting tumor...")
109
+             
110
+            
111
+             predicted_class, confidence_score = predict_image(uploaded_file, model)
112
+             
113
+            
114
+             
115
+
116
+             if predicted_class == 'no_tumor':
117
+                 result_label = f" **Prediction: No Tumor**"
118
+             else:
119
+                 result_label = f" **Prediction: Tumor ({predicted_class.replace('_', ' ').title()})**"
120
+             
121
+             st.success(" Analysis Complete")
122
+             st.subheader(result_label)
123
+             st.metric(label="Confidence Score", value=f"{confidence_score:.2f}%")
124
+             
125
+             st.write("---")
126
+
127
+ with col2:
128
+     st.header("Results and Interpretation")
129
+     st.info("The system uses Transfer Learning (VGG16) to classify the image into four categories: Glioma, Meningioma, Pituitary, or No Tumor.")
130
+    
131
+
132
+     if uploaded_file is None:
133
+         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