LovnishVerma commited on
Commit
9318c19
·
verified ·
1 Parent(s): 405c8d8

Delete BrainTumorPP

Browse files
BrainTumorPP/.gitattributes DELETED
@@ -1,35 +0,0 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz 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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
BrainTumorPP/Dockerfile DELETED
@@ -1,20 +0,0 @@
1
- # Using Python 3.9 base image
2
- FROM python:3.9
3
-
4
- # Set the working directory to /code
5
- WORKDIR /code
6
-
7
- # Install necessary system dependencies, including libGL.so.1
8
- RUN apt-get update && apt-get install -y libgl1 && apt-get clean
9
-
10
- # Copy requirements.txt to /code
11
- COPY ./requirements.txt /code/requirements.txt
12
-
13
- # Install dependencies from requirements.txt
14
- RUN pip install --no-cache-dir --upgrade -r requirements.txt
15
-
16
- # Copy the entire project content to /code
17
- COPY . /code
18
-
19
- # CMD to run Gunicorn
20
- CMD ["gunicorn", "main:app", "-b", "0.0.0.0:7860"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
BrainTumorPP/README.md DELETED
@@ -1,11 +0,0 @@
1
- ---
2
- title: Flask
3
- emoji: 🚀
4
- colorFrom: yellow
5
- colorTo: red
6
- sdk: docker
7
- pinned: false
8
- license: cc
9
- ---
10
-
11
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
BrainTumorPP/cnn.txt DELETED
@@ -1,67 +0,0 @@
1
- In this Flask application, the model you're loading (`braintumor_model`) is a Convolutional Neural Network (CNN) trained to detect brain tumors in images. The CNN model is used to classify the images after preprocessing and passing them through the network.
2
- Here's a breakdown of how CNN is used and how it's integrated into your Flask app:
3
-
4
- Key Concepts of CNN in Your Application
5
-
6
- 1. Convolutional Layers (Feature Extraction):
7
- CNNs are designed to automatically learn spatial hierarchies of features from the input image (in this case, brain tumor images).
8
- The convolutional layers apply convolutional filters (kernels) that detect low-level features like edges, corners, and textures. As the image passes through multiple layers of convolutions, it progressively detects more complex features like shapes or regions of interest.
9
-
10
- 2. Pooling Layers (Downsampling):
11
- After convolutions, pooling layers (often Max Pooling) are applied to reduce the spatial dimensions of the feature maps.
12
- This helps in reducing the computational complexity while preserving important features.
13
-
14
- 3. Fully Connected Layers (Classification):
15
- After the feature extraction and downsampling, the CNN typically flattens the resulting feature maps into a 1D vector and feeds it into fully connected layers (Dense layers).
16
- The final fully connected layer outputs the prediction, which can be a binary classification in your case (whether a tumor is present or not).
17
-
18
- 4. Activation Functions (Non-linearity):
19
- The CNN typically uses activation functions like ReLU (Rectified Linear Unit) after each convolutional and fully connected layer to introduce non-linearity, allowing the model to learn complex patterns.
20
- The final layer likely uses a sigmoid activation function (since it's a binary classification) to output a value between 0 and 1. A value close to 0 indicates no tumor, while a value close to 1 indicates a tumor.
21
-
22
- How the CNN Works in Your Flask App
23
-
24
- 1. Model Loading:
25
- You load a pre-trained CNN model using `braintumor_model = load_model('models/braintumor.h5')`.
26
- This model is assumed to be trained on a dataset of brain images, where it learns to classify whether a brain tumor is present or not.
27
-
28
- 2. Image Preprocessing:
29
- Before the image is fed into the model for prediction, it's preprocessed using two main functions:
30
- `crop_imgs`: Crops the region of interest (ROI) where the tumor is likely located. This reduces the unnecessary image data, focusing the model on the area that matters most.
31
- `preprocess_imgs`: Resizes the image to the target size (224x224), which is the input size expected by the CNN. The CNN likely uses VGG16 or a similar architecture, which typically accepts 224x224 pixel images.
32
-
33
- 3. Image Prediction:
34
- - Once the image is preprocessed, it is passed into the CNN for prediction:
35
-
36
- pred = braintumor_model.predict(img)
37
-
38
- The model outputs a value between 0 and 1. This is the probability that the image contains a tumor.
39
- If `pred < 0.5`, the model classifies the image as **no tumor** (`pred = 0`).
40
- If `pred >= 0.5`, the model classifies the image as **tumor detected** (`pred = 1`).
41
-
42
- 4. Displaying Results:
43
- Based on the prediction, the result is displayed on the `resultbt.html` page, where the user is informed if the image contains a tumor or not.
44
-
45
- A High-Level Overview of CNN in Action:
46
- Image Input: A brain MRI image is uploaded by the user.
47
- Preprocessing: The image is cropped to focus on the relevant region (tumor area), resized to the required input size for the CNN, and normalized (if necessary).
48
- CNN Prediction: The processed image is passed through the CNN, which performs feature extraction and classification. The output is a probability score (0 or 1) indicating the likelihood of a tumor being present.
49
- Output: The app displays whether a tumor is present or not based on the CNN's prediction.
50
-
51
- CNN Model Workflow (High-Level)
52
-
53
- 1. Convolution Layers: Learn to detect features like edges, textures, and structures in the image.
54
- 2. Pooling Layers: Reduce the dimensionality while retaining key features.
55
- 3. Fully Connected Layers: Use the learned features to make a classification decision (tumor vs. no tumor).
56
- 4. Prediction: The model outputs a binary classification result: `0` (no tumor) or `1` (tumor detected).
57
-
58
- Training of the CNN Model (Assumed):
59
- The model (`braintumor_model.h5`) you are loading in the app is assumed to be pre-trained on a large dataset of brain tumor images (e.g., MRI scans), where it has learned the distinguishing features of images with and without tumors. Typically, this training would involve:
60
- Convolutional layers for feature extraction.
61
- Pooling layers to reduce spatial dimensions.
62
- Fully connected layers to classify the image as containing a tumor or not.
63
-
64
- This pre-trained model can then be used for inference (prediction) on new images that are uploaded by the user.
65
-
66
- Your application uses a Convolutional Neural Network (CNN) to detect brain tumors in images.
67
- The CNN is trained to learn features from medical images, and when a user uploads an image, the app preprocesses it, passes it through the model, and provides a prediction (tumor detected or not). The model’s decision is based on its learned understanding of what a tumor looks like, making it an effective tool for automatic detection.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
BrainTumorPP/explain.md DELETED
@@ -1,213 +0,0 @@
1
- ### **Code Explanation for Brain Tumor Detection Application Using Flask**
2
-
3
- This Flask-based application allows users to upload an image (like an MRI scan) to predict if a brain tumor is detected using a pre-trained CNN (Convolutional Neural Network) model. The results, along with user details, are saved in a MongoDB database for review.
4
-
5
- ---
6
-
7
- ### **1. Importing Required Libraries**
8
-
9
- ```python
10
- from flask import Flask, flash, request, redirect, render_template
11
- import os
12
- import cv2
13
- import imutils
14
- import numpy as np
15
- from tensorflow.keras.models import load_model
16
- from werkzeug.utils import secure_filename
17
- import tempfile
18
- from pymongo import MongoClient
19
- from datetime import datetime
20
- ```
21
-
22
- - **Flask**: A lightweight web framework to create web applications.
23
- - **OpenCV (cv2)**: Library for image processing.
24
- - **imutils**: Helper functions for image manipulation.
25
- - **NumPy**: Array and mathematical operations.
26
- - **TensorFlow/Keras**: To load the pre-trained brain tumor detection model.
27
- - **MongoDB**: To store user inputs and model predictions.
28
- - **Werkzeug**: For securely handling file uploads.
29
- - **Datetime**: To save the timestamp for each prediction.
30
-
31
- ---
32
-
33
- ### **2. Loading the Pre-trained Model**
34
-
35
- ```python
36
- braintumor_model = load_model('models/braintumor.h5')
37
- ```
38
- - The brain tumor model (`braintumor.h5`) is loaded. This is a CNN-based model trained to detect brain tumors from images.
39
-
40
- ---
41
-
42
- ### **3. Flask Application Configuration**
43
-
44
- ```python
45
- app = Flask(__name__)
46
- app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0 # Disable caching
47
- app.secret_key = "nielitchandigarhpunjabpolice"
48
- ```
49
-
50
- - Flask is initialized, and caching for images is disabled to ensure updated images load after upload.
51
- - A **secret key** is set for session management, which helps in managing messages (like flash messages).
52
-
53
- ---
54
-
55
- ### **4. MongoDB Connection**
56
-
57
- ```python
58
- client = MongoClient("mongodb+srv://test:test@cluster0.sxci1.mongodb.net/?retryWrites=true&w=majority")
59
- db = client['brain_tumor_detection'] # Database name
60
- collection = db['predictions'] # Collection name
61
- ```
62
- - Connects to **MongoDB Atlas** (cloud-hosted database).
63
- - A database named `brain_tumor_detection` and collection `predictions` are created to store user details and predictions.
64
-
65
- ---
66
-
67
- ### **5. File Upload Helper Function**
68
-
69
- ```python
70
- ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg'])
71
-
72
- def allowed_file(filename):
73
- return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
74
- ```
75
- - Only files with extensions **png, jpg, jpeg** are allowed to ensure proper image input.
76
-
77
- ---
78
-
79
- ### **6. Image Preprocessing**
80
-
81
- **a. `preprocess_imgs`: Resizing Images**
82
-
83
- ```python
84
- def preprocess_imgs(set_name, img_size):
85
- set_new = []
86
- for img in set_name:
87
- img = cv2.resize(img, dsize=img_size, interpolation=cv2.INTER_CUBIC)
88
- set_new.append(img)
89
- return np.array(set_new)
90
- ```
91
- - Resizes the input image to a specific size (224x224) required by the model.
92
-
93
- **b. `crop_imgs`: Region of Interest (ROI) Extraction**
94
-
95
- ```python
96
- def crop_imgs(set_name, add_pixels_value=0):
97
- set_new = []
98
- for img in set_name:
99
- gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
100
- gray = cv2.GaussianBlur(gray, (5, 5), 0)
101
- thresh = cv2.threshold(gray, 45, 255, cv2.THRESH_BINARY)[1]
102
- cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
103
- c = max(cnts, key=cv2.contourArea)
104
- extLeft = tuple(c[c[:, :, 0].argmin()][0])
105
- extRight = tuple(c[c[:, :, 0].argmax()][0])
106
- extTop = tuple(c[c[:, :, 1].argmin()][0])
107
- extBot = tuple(c[c[:, :, 1].argmax()][0])
108
- new_img = img[extTop[1]:extBot[1], extLeft[0]:extRight[0]].copy()
109
- set_new.append(new_img)
110
- return np.array(set_new)
111
- ```
112
- - This function identifies the **region of interest (ROI)**, cropping only the area where the brain is located for better accuracy.
113
-
114
- ---
115
-
116
- ### **7. Routes in Flask**
117
-
118
- **a. `/` Route - Main Page**
119
-
120
- ```python
121
- @app.route('/')
122
- def brain_tumor():
123
- return render_template('braintumor.html')
124
- ```
125
- - Displays the main upload form (`braintumor.html`).
126
-
127
- **b. `/resultbt` Route - Prediction**
128
-
129
- ```python
130
- @app.route('/resultbt', methods=['POST'])
131
- def resultbt():
132
- # 1. Extract user inputs
133
- firstname = request.form['firstname']
134
- file = request.files['file']
135
-
136
- # 2. Validate image
137
- if file and allowed_file(file.filename):
138
- temp_file = tempfile.NamedTemporaryFile(delete=False)
139
- file.save(temp_file.name)
140
-
141
- # 3. Process Image
142
- img = cv2.imread(temp_file.name)
143
- img = crop_imgs([img])
144
- img = preprocess_imgs([img], (224, 224))
145
-
146
- # 4. Predict
147
- pred = braintumor_model.predict(img)
148
- prediction = 'Tumor Detected' if pred[0][0] >= 0.5 else 'No Tumor Detected'
149
- confidence_score = float(pred[0][0])
150
-
151
- # 5. Save to MongoDB
152
- result = {
153
- "firstname": firstname,
154
- "prediction": prediction,
155
- "confidence_score": confidence_score,
156
- "timestamp": datetime.utcnow()
157
- }
158
- collection.insert_one(result)
159
-
160
- # 6. Return Results
161
- return render_template('resultbt.html', r=prediction)
162
- else:
163
- flash('Invalid file format!')
164
- return redirect(request.url)
165
- ```
166
- - **Step-by-step Flow**:
167
- 1. Accept user inputs and uploaded image.
168
- 2. Validate the file format.
169
- 3. Preprocess the image (crop and resize).
170
- 4. Use the CNN model to predict if there is a tumor.🚀
171
- 5. Save the prediction and user details to MongoDB.
172
- 6. Return the result.
173
-
174
- **c. `/dbresults` Route - Fetch Predictions**
175
-
176
- ```python
177
- @app.route('/dbresults')
178
- def dbresults():
179
- all_results = collection.find().sort("timestamp", -1)
180
- tumor_count = sum(1 for r in all_results if r['prediction'] == 'Tumor Detected')
181
- total_patients = collection.count_documents({})
182
- return render_template('dbresults.html', total_patients=total_patients, tumor_count=tumor_count)
183
- ```
184
- - Fetches all predictions from MongoDB and aggregates results (total patients, tumors detected).
185
-
186
- ---
187
-
188
- ### **8. Running the App**
189
-
190
- ```python
191
- if __name__ == '__main__':
192
- app.run(debug=True)
193
- ```
194
- - Runs the Flask application in **debug mode**.
195
-
196
- ---
197
-
198
- ### **Summary of Flow**
199
- 1. User uploads an MRI image and provides basic details.
200
- 2. Image is preprocessed (cropped, resized) for the CNN model.
201
- 3. The model predicts if a **brain tumor is detected** or not.
202
- 4. Results are stored in MongoDB and displayed back to the user.
203
- 5. Admins can view all results via the `/dbresults` route.
204
-
205
- ---
206
-
207
- ### **Tips**
208
- 1. **Flask Routes** handle user requests (`/`, `/resultbt`, `/dbresults`).
209
- 2. **OpenCV** helps preprocess images.
210
- 3. **MongoDB** stores user details and model predictions.
211
- 4. **Model Prediction** is done via a pre-trained Keras model.
212
- 5. Templates (`braintumor.html`, `resultbt.html`) are used to display data.
213
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
BrainTumorPP/main.py DELETED
@@ -1,157 +0,0 @@
1
- from flask import Flask, flash, request, redirect, render_template
2
- import os
3
- import cv2
4
- import imutils
5
- import numpy as np
6
- from tensorflow.keras.models import load_model
7
- from werkzeug.utils import secure_filename
8
- import tempfile
9
- from pymongo import MongoClient
10
- from datetime import datetime
11
-
12
- # Load the Brain Tumor CNN Model
13
- braintumor_model = load_model('models/braintumor.h5')
14
-
15
- # Configuring Flask application
16
- app = Flask(__name__)
17
- app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0 # Disable caching for images
18
- app.secret_key = "nielitchandigarhpunjabpolice" # Secret key for session management
19
-
20
- # Allowed image file extensions
21
- ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg'])
22
-
23
- # Connect to MongoDB Atlas
24
- client = MongoClient("mongodb+srv://test:test@cluster0.sxci1.mongodb.net/?retryWrites=true&w=majority")
25
- db = client['brain_tumor_detection'] # Database name
26
- collection = db['predictions'] # Collection name
27
-
28
- def allowed_file(filename):
29
- """Check if the file is a valid image format (png, jpg, jpeg)."""
30
- return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
31
-
32
- def preprocess_imgs(set_name, img_size):
33
- """
34
- Preprocess images by resizing them to the target size (224x224 for VGG16)
35
- and applying appropriate resizing techniques.
36
- """
37
- set_new = []
38
- for img in set_name:
39
- img = cv2.resize(img, dsize=img_size, interpolation=cv2.INTER_CUBIC) # Resize image
40
- set_new.append(img)
41
- return np.array(set_new)
42
-
43
- def crop_imgs(set_name, add_pixels_value=0):
44
- """
45
- Crop the region of interest (ROI) in the image for brain tumor detection.
46
- """
47
- set_new = []
48
- for img in set_name:
49
- gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
50
- gray = cv2.GaussianBlur(gray, (5, 5), 0)
51
- thresh = cv2.threshold(gray, 45, 255, cv2.THRESH_BINARY)[1]
52
- thresh = cv2.erode(thresh, None, iterations=2)
53
- thresh = cv2.dilate(thresh, None, iterations=2)
54
- cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
55
- cnts = imutils.grab_contours(cnts)
56
- c = max(cnts, key=cv2.contourArea)
57
- extLeft = tuple(c[c[:, :, 0].argmin()][0])
58
- extRight = tuple(c[c[:, :, 0].argmax()][0])
59
- extTop = tuple(c[c[:, :, 1].argmin()][0])
60
- extBot = tuple(c[c[:, :, 1].argmax()][0])
61
- ADD_PIXELS = add_pixels_value
62
- new_img = img[extTop[1]-ADD_PIXELS:extBot[1]+ADD_PIXELS,
63
- extLeft[0]-ADD_PIXELS:extRight[0]+ADD_PIXELS].copy()
64
- set_new.append(new_img)
65
- return np.array(set_new)
66
-
67
- @app.route('/')
68
- def brain_tumor():
69
- """Render the HTML form for the user to upload an image."""
70
- return render_template('braintumor.html')
71
-
72
- @app.route('/resultbt', methods=['POST'])
73
- def resultbt():
74
- """Process the uploaded image and save prediction results to MongoDB."""
75
- if request.method == 'POST':
76
- firstname = request.form['firstname']
77
- lastname = request.form['lastname']
78
- email = request.form['email']
79
- phone = request.form['phone']
80
- gender = request.form['gender']
81
- age = request.form['age']
82
- file = request.files['file']
83
-
84
- if file and allowed_file(file.filename):
85
- temp_file = tempfile.NamedTemporaryFile(delete=False)
86
- filename = secure_filename(file.filename)
87
- file.save(temp_file.name)
88
-
89
- flash('Image successfully uploaded and displayed below')
90
-
91
- # Process the image
92
- img = cv2.imread(temp_file.name)
93
- img = crop_imgs([img])
94
- img = img.reshape(img.shape[1:])
95
- img = preprocess_imgs([img], (224, 224))
96
-
97
- # Make prediction
98
- pred = braintumor_model.predict(img)
99
- prediction = 'Tumor Detected' if pred[0][0] >= 0.5 else 'No Tumor Detected'
100
- confidence_score = float(pred[0][0])
101
-
102
- # Prepare data for MongoDB
103
- result = {
104
- "firstname": firstname,
105
- "lastname": lastname,
106
- "email": email,
107
- "phone": phone,
108
- "gender": gender,
109
- "age": age,
110
- "image_name": filename,
111
- "prediction": prediction,
112
- "confidence_score": confidence_score,
113
- "timestamp": datetime.utcnow()
114
- }
115
-
116
- # Insert data into MongoDB
117
- collection.insert_one(result)
118
-
119
- # Return the result to the user
120
- return render_template('resultbt.html', filename=filename, fn=firstname, ln=lastname, age=age, r=prediction, gender=gender)
121
- else:
122
- flash('Allowed image types are - png, jpg, jpeg')
123
- return redirect(request.url)
124
-
125
- @app.route('/dbresults')
126
- def dbresults():
127
- """Fetch all results from MongoDB, show aggregated data, and render in a template."""
128
- # Fetch all documents from MongoDB, sorted by timestamp in descending order
129
- all_results = collection.find().sort("timestamp", -1) # Sort by timestamp, latest first
130
-
131
- # Convert cursor to a list of dictionaries
132
- results_list = []
133
- tumor_count = 0
134
- no_tumor_count = 0
135
-
136
- for result in all_results:
137
- result['_id'] = str(result['_id']) # Convert ObjectId to string for JSON serialization
138
- results_list.append(result)
139
-
140
- # Count total patients with tumor and without tumor
141
- if result['prediction'] == 'Tumor Detected':
142
- tumor_count += 1
143
- else:
144
- no_tumor_count += 1
145
-
146
- total_patients = len(results_list) # Total number of patients
147
-
148
- # Pass the results and aggregated counts to the HTML template
149
- return render_template('dbresults.html',
150
- results=results_list,
151
- total_patients=total_patients,
152
- tumor_count=tumor_count,
153
- no_tumor_count=no_tumor_count)
154
-
155
-
156
- if __name__ == '__main__':
157
- app.run(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
BrainTumorPP/models/braintumor.h5 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:7a756efdea8aa2748819ea2ccfbf2e0f4dad62236726532adb50439f06f55165
3
- size 59111488
 
 
 
 
BrainTumorPP/requirements.txt DELETED
@@ -1,16 +0,0 @@
1
- flask
2
- flask-cors
3
- gunicorn
4
- Jinja2
5
- pandas
6
- numpy
7
- scikit-learn
8
- tensorflow
9
- imutils
10
- opencv-python
11
- matplotlib
12
- Werkzeug
13
- Pillow
14
- pymongo
15
- datetime
16
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
BrainTumorPP/sampleimages/No tumor (2).jpeg DELETED
Binary file (79.7 kB)
 
BrainTumorPP/sampleimages/doubt.jpg DELETED
Binary file (7.65 kB)
 
BrainTumorPP/sampleimages/no tumor.jpeg DELETED
Binary file (5.15 kB)
 
BrainTumorPP/sampleimages/yes tumor (2).jpg DELETED
Binary file (5.76 kB)
 
BrainTumorPP/sampleimages/yes tumor.png DELETED
Binary file (60.8 kB)
 
BrainTumorPP/sampleimages/yes tumor1.jpg DELETED
Binary file (41 kB)
 
BrainTumorPP/static/brain.gif DELETED
Binary file (310 kB)
 
BrainTumorPP/templates/braintumor.html DELETED
@@ -1,230 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
-
4
- <head>
5
- <!-- Required meta tags -->
6
- <meta charset="utf-8">
7
- <meta name="viewport" content="width=device-width, initial-scale=1">
8
-
9
- <!-- Bootstrap CSS -->
10
- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet"
11
- integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
12
-
13
- <!-- Custom Styles -->
14
- <style type="text/css">
15
- body {
16
- background-image: url(static/brain.gif);
17
- background-position: center;
18
- background-size: cover;
19
- font-family: 'Roboto', sans-serif;
20
- margin-top: 40px;
21
- color: #fff;
22
- }
23
-
24
- .navbar {
25
- background-color: #212121 !important;
26
- }
27
-
28
- .navbar-brand {
29
- font-weight: bold;
30
- font-size: 1.5rem;
31
- }
32
-
33
- .regform {
34
- background-color: rgba(0, 0, 0, 0.6);
35
- padding: 20px;
36
- text-align: center;
37
- border-radius: 15px 15px 0 0;
38
- box-shadow: 0 10px 15px rgba(0, 0, 0, 0.5);
39
- margin-top: 20px;
40
- }
41
-
42
- .regform h1 {
43
- font-size: 2rem;
44
- font-weight: bold;
45
- }
46
-
47
- .main-form {
48
- background-color: rgba(0, 0, 0, 0.7);
49
- margin: 20px auto;
50
- padding: 30px;
51
- border-radius: 10px;
52
- max-width: 900px;
53
- }
54
-
55
- .form-group label {
56
- font-size: 1rem;
57
- font-weight: 500;
58
- }
59
-
60
- .form-control {
61
- border-radius: 5px;
62
- box-shadow: none;
63
- border: 2px solid #bbb;
64
- margin-bottom: 15px;
65
- }
66
-
67
- .form-control:focus {
68
- border-color: #5cb85c;
69
- }
70
-
71
- .btn-submit {
72
- background-color: #28a745;
73
- color: white;
74
- font-size: 1.1rem;
75
- padding: 15px 30px;
76
- border-radius: 5px;
77
- border: none;
78
- transition: background-color 0.3s ease;
79
- }
80
-
81
- .btn-submit:hover {
82
- background-color: #218838;
83
- }
84
-
85
- .form-text {
86
- font-size: 0.85rem;
87
- }
88
-
89
- .col-md-6 {
90
- margin-bottom: 15px;
91
- }
92
-
93
- .col-md-6 label,
94
- .col-md-6 input,
95
- .col-md-6 select {
96
- font-size: 1rem;
97
- }
98
-
99
- .footer {
100
- text-align: center;
101
- margin-top: 30px;
102
- font-size: 0.9rem;
103
- color: #ccc;
104
- }
105
-
106
- /* Responsive design */
107
- @media (max-width: 767px) {
108
- .regform h1 {
109
- font-size: 1.6rem;
110
- }
111
-
112
- .main-form {
113
- padding: 20px;
114
- }
115
- }
116
- </style>
117
-
118
- <title>Brain Tumor Detection</title>
119
- </head>
120
-
121
- <body>
122
- <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
123
- <div class="container-fluid">
124
- <a class="navbar-brand" href="/">CNN Brain Tumor Detection</a>
125
- <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
126
- aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
127
- <span class="navbar-toggler-icon"></span>
128
- </button>
129
- <div class="collapse navbar-collapse" id="navbarNav">
130
- <ul class="navbar-nav ms-auto">
131
- <li class="nav-item">
132
- <a class="nav-link" href="/dbresults">View MongoDB Results</a>
133
- </li>
134
- </ul>
135
- </div>
136
- </div>
137
- </nav>
138
-
139
- <div class="regform">
140
- <h1>Brain Tumor Detection Form</h1>
141
- </div>
142
-
143
- <div class="container">
144
- <form action="resultbt" class="main-form needs-validation" method="POST" enctype="multipart/form-data" novalidate>
145
- <div class="row">
146
- <div class="col-md-6">
147
- <div class="form-group">
148
- <label for="firstname">First Name</label>
149
- <input type="text" name="firstname" id="firstname" class="form-control" required>
150
- </div>
151
- </div>
152
- <div class="col-md-6">
153
- <div class="form-group">
154
- <label for="lastname">Last Name</label>
155
- <input type="text" name="lastname" id="lastname" class="form-control" required>
156
- </div>
157
- </div>
158
- </div>
159
-
160
- <div class="form-group">
161
- <label for="phone">Phone Number</label>
162
- <input type="tel" name="phone" id="phone" class="form-control" required>
163
- <small class="form-text">* Include your area code</small>
164
- </div>
165
-
166
- <div class="form-group">
167
- <label for="email">Email Address</label>
168
- <input type="email" name="email" id="email" class="form-control" required>
169
- </div>
170
-
171
- <div class="row">
172
- <div class="col-md-6">
173
- <div class="form-group">
174
- <label for="gender">Gender</label>
175
- <select name="gender" id="gender" class="form-control" required>
176
- <option value="male">Male</option>
177
- <option value="female">Female</option>
178
- </select>
179
- </div>
180
- </div>
181
- <div class="col-md-6">
182
- <div class="form-group">
183
- <label for="age">Age</label>
184
- <input type="number" name="age" id="age" class="form-control" required>
185
- </div>
186
- </div>
187
- </div>
188
-
189
- <div class="form-group">
190
- <label for="file">Upload Your Brain MRI</label>
191
- <input type="file" class="form-control" id="file" name="file" required>
192
- </div>
193
-
194
- <div class="text-center">
195
- <button type="submit" class="btn-submit">Submit</button>
196
- </div>
197
- </form>
198
- </div>
199
-
200
- <div class="footer">
201
- <p>&copy; 2024 Brain Tumor Detection - All Rights Reserved</p>
202
- </div>
203
-
204
- <!-- Bootstrap Bundle with Popper -->
205
- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js"
206
- integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf"
207
- crossorigin="anonymous"></script>
208
-
209
- <!-- Enable Bootstrap validation -->
210
- <script>
211
- (function () {
212
- 'use strict'
213
- // Fetch all the forms we want to apply custom Bootstrap validation styles to
214
- var forms = document.querySelectorAll('.needs-validation')
215
- // Loop over them and prevent submission
216
- Array.prototype.slice.call(forms)
217
- .forEach(function (form) {
218
- form.addEventListener('submit', function (event) {
219
- if (!form.checkValidity()) {
220
- event.preventDefault()
221
- event.stopPropagation()
222
- }
223
- form.classList.add('was-validated')
224
- }, false)
225
- })
226
- })()
227
- </script>
228
- </body>
229
-
230
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
BrainTumorPP/templates/dbresults.html DELETED
@@ -1,151 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Database Results</title>
7
-
8
- <!-- Custom Styles -->
9
- <style>
10
- body {
11
- font-family: 'Roboto', sans-serif;
12
- background-image: url('static/brain.gif');
13
- background-position: center;
14
- background-size: cover;
15
- color: #fff;
16
- padding-top: 20px;
17
- }
18
-
19
- h1 {
20
- text-align: center;
21
- font-size: 2rem;
22
- font-weight: bold;
23
- color: #fff;
24
- }
25
-
26
- .stats-container {
27
- width: 90%;
28
- margin: 20px auto;
29
- text-align: center;
30
- background-color: rgba(0, 0, 0, 0.7);
31
- padding: 20px;
32
- border-radius: 10px;
33
- box-shadow: 0 5px 10px rgba(0, 0, 0, 0.5);
34
- }
35
-
36
- .stats-container h2 {
37
- font-size: 1.5rem;
38
- margin: 10px 0;
39
- color: #fff;
40
- }
41
-
42
- table {
43
- width: 90%;
44
- margin: 30px auto;
45
- border-collapse: collapse;
46
- background-color: rgba(0, 0, 0, 0.6);
47
- border-radius: 10px;
48
- box-shadow: 0 10px 20px rgba(0, 0, 0, 0.6);
49
- }
50
-
51
- th, td {
52
- border: 1px solid #ddd;
53
- padding: 12px 18px;
54
- text-align: center;
55
- font-size: 1.1rem;
56
- }
57
-
58
- th {
59
- background-color: #343a40;
60
- color: #fff;
61
- }
62
-
63
- td {
64
- background-color: rgba(255, 255, 255, 0.1);
65
- color: #fff;
66
- }
67
-
68
- tr:nth-child(even) {
69
- background-color: rgba(255, 255, 255, 0.15);
70
- }
71
-
72
- tr:hover {
73
- background-color: rgba(255, 255, 255, 0.3);
74
- }
75
-
76
- .footer {
77
- text-align: center;
78
- margin-top: 30px;
79
- color: #ccc;
80
- font-size: 0.9rem;
81
- }
82
-
83
- @media (max-width: 767px) {
84
- h1 {
85
- font-size: 1.6rem;
86
- }
87
-
88
- table {
89
- width: 100%;
90
- }
91
-
92
- th, td {
93
- padding: 10px 12px;
94
- font-size: 1rem;
95
- }
96
- }
97
- </style>
98
- </head>
99
- <body>
100
-
101
- <!-- Page Title -->
102
- <h1>Stored Results</h1>
103
-
104
- <!-- Stats Section -->
105
- <div class="stats-container">
106
- <h2>Total Patients: {{ total_patients }}</h2>
107
- <h2>Total with Tumor: {{ tumor_count }}</h2>
108
- <h2>Total without Tumor: {{ no_tumor_count }}</h2>
109
- </div>
110
-
111
- <!-- Table Container -->
112
- <div class="table-container">
113
- <table>
114
- <thead>
115
- <tr>
116
- <th>First Name</th>
117
- <th>Last Name</th>
118
- <th>Email</th>
119
- <th>Phone</th>
120
- <th>Gender</th>
121
- <th>Age</th>
122
- <th>Prediction</th>
123
- <th>Confidence Score</th>
124
- <th>Timestamp</th>
125
- </tr>
126
- </thead>
127
- <tbody>
128
- {% for result in results %}
129
- <tr>
130
- <td>{{ result.firstname }}</td>
131
- <td>{{ result.lastname }}</td>
132
- <td>{{ result.email }}</td>
133
- <td>{{ result.phone }}</td>
134
- <td>{{ result.gender }}</td>
135
- <td>{{ result.age }}</td>
136
- <td>{{ result.prediction }}</td>
137
- <td>{{ result.confidence_score }}</td>
138
- <td>{{ result.timestamp }}</td>
139
- </tr>
140
- {% endfor %}
141
- </tbody>
142
- </table>
143
- </div>
144
-
145
- <!-- Footer -->
146
- <div class="footer">
147
- <p>&copy; 2024 Brain Tumor Detection - All Rights Reserved</p>
148
- </div>
149
-
150
- </body>
151
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
BrainTumorPP/templates/resultbt.html DELETED
@@ -1,147 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
-
4
- <head>
5
- <!-- Required meta tags -->
6
- <meta charset="utf-8">
7
- <meta name="viewport" content="width=device-width, initial-scale=1">
8
-
9
- <!-- Bootstrap CSS -->
10
- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet"
11
- integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
12
-
13
- <!-- Custom Styles -->
14
- <style type="text/css">
15
- body {
16
- background-image: url(static/brain.gif);
17
- background-position: center;
18
- background-size: cover;
19
- font-family: 'Roboto', sans-serif;
20
- margin-top: 40px;
21
- color: #fff;
22
- }
23
-
24
- .navbar {
25
- background-color: #212121 !important;
26
- }
27
-
28
- .navbar-brand {
29
- font-weight: bold;
30
- font-size: 1.5rem;
31
- }
32
-
33
- .regform {
34
- width: 800px;
35
- background-color: rgba(253, 252, 252, 0.8);
36
- margin: auto;
37
- color: #0f0f0f;
38
- padding: 20px;
39
- text-align: center;
40
- border-radius: 15px 15px 0px 0px;
41
- box-shadow: 0 10px 15px rgba(0, 0, 0, 0.5);
42
- }
43
-
44
- .regform h1 {
45
- font-size: 2rem;
46
- font-weight: bold;
47
- }
48
-
49
- .main-form {
50
- width: 800px;
51
- margin: auto;
52
- background-color: rgba(0, 0, 0, 0.7);
53
- padding: 30px;
54
- border-radius: 10px;
55
- color: #FFFFFF;
56
- box-shadow: 0 10px 15px rgba(0, 0, 0, 0.7);
57
- }
58
-
59
- .main-form p {
60
- font-size: 1.2rem;
61
- line-height: 1.8;
62
- }
63
-
64
- .main-form p i {
65
- font-style: italic;
66
- color: #28a745;
67
- }
68
-
69
- .footer {
70
- text-align: center;
71
- margin-top: 30px;
72
- font-size: 0.9rem;
73
- color: #ccc;
74
- }
75
-
76
- /* Responsive design */
77
- @media (max-width: 767px) {
78
- .regform h1 {
79
- font-size: 1.6rem;
80
- }
81
-
82
- .main-form {
83
- padding: 20px;
84
- }
85
-
86
- .main-form p {
87
- font-size: 1rem;
88
- }
89
- }
90
- </style>
91
-
92
- <title>Brain Tumor Detection</title>
93
- </head>
94
-
95
- <body>
96
- <!-- Navbar -->
97
- <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
98
- <div class="container-fluid">
99
- <a class="navbar-brand" href="/">CNN</a>
100
- <button class="navbar-toggler" type="button" data-bs-toggle="collapse"
101
- data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false"
102
- aria-label="Toggle navigation">
103
- <span class="navbar-toggler-icon"></span>
104
- </button>
105
- <div class="collapse navbar-collapse" id="navbarSupportedContent">
106
- <ul class="navbar-nav ms-auto mb-2 mb-lg-0">
107
- <li class="nav-item">
108
- <a class="nav-link" href="/dbresults">MongoDB</a>
109
- </li>
110
- </ul>
111
- </div>
112
- </div>
113
- </nav>
114
-
115
- <!-- Result Form -->
116
- <div class='regform mt-3'>
117
- <h1>Brain Tumor Test Results</h1>
118
- </div>
119
-
120
- <div class='main-form'>
121
- <div>
122
- <div class="col" style='margin-top: 30px; margin-bottom: 30px;'>
123
- <p><strong>First Name:</strong> {{fn}}</p>
124
- <p><strong>Last Name:</strong> {{ln}}</p>
125
- <p><strong>Age:</strong> {{age}}</p>
126
- <p><strong>Gender:</strong> {{gender}}</p>
127
-
128
-
129
- <div>
130
- <p><strong>Result:</strong> <i>{{r}}</i></p>
131
- </div>
132
- </div>
133
- </div>
134
- </div>
135
-
136
- <!-- Footer -->
137
- <div class="footer">
138
- <p>&copy; 2024 Brain Tumor Detection - All Rights Reserved</p>
139
- </div>
140
-
141
- <!-- Bootstrap Bundle with Popper -->
142
- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js"
143
- integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf"
144
- crossorigin="anonymous"></script>
145
- </body>
146
-
147
- </html>