Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -88,7 +88,6 @@ def resultbt():
|
|
88 |
|
89 |
flash('Image successfully uploaded and displayed below')
|
90 |
|
91 |
-
|
92 |
try:
|
93 |
# Process the image
|
94 |
img = cv2.imread(temp_file.name)
|
@@ -96,37 +95,16 @@ def resultbt():
|
|
96 |
img = crop_imgs([img])
|
97 |
img = img.reshape(img.shape[1:]) # Reshape to (height, width, channels)
|
98 |
img = preprocess_imgs([img], (128, 128)) # Resize to (128, 128, 3)
|
99 |
-
|
100 |
# Ensure the input shape matches the model's expectation
|
101 |
img = img[0] # Remove unnecessary extra dimension
|
102 |
img = np.expand_dims(img, axis=0) # Add batch dimension to match (1, 128, 128, 3)
|
103 |
-
|
104 |
# Make prediction
|
105 |
pred = braintumor_model.predict(img)
|
106 |
prediction = 'Tumor Detected' if pred[0][0] >= 0.5 else 'No Tumor Detected'
|
107 |
confidence_score = float(pred[0][0])
|
108 |
|
109 |
-
# Prepare data for MongoDB
|
110 |
-
result = {
|
111 |
-
"firstname": firstname,
|
112 |
-
"lastname": lastname,
|
113 |
-
"email": email,
|
114 |
-
"phone": phone,
|
115 |
-
"gender": gender,
|
116 |
-
"age": age,
|
117 |
-
"image_name": filename,
|
118 |
-
"prediction": prediction,
|
119 |
-
"confidence_score": confidence_score,
|
120 |
-
"timestamp": datetime.utcnow()
|
121 |
-
}
|
122 |
-
|
123 |
-
# Insert data into MongoDB
|
124 |
-
collection.insert_one(result)
|
125 |
-
|
126 |
-
# Return the result to the user
|
127 |
-
return render_template('resultbt.html', filename=filename, fn=firstname, ln=lastname, age=age, r=prediction, gender=gender)
|
128 |
-
|
129 |
-
|
130 |
# Prepare data for MongoDB
|
131 |
result = {
|
132 |
"firstname": firstname,
|
@@ -152,7 +130,6 @@ def resultbt():
|
|
152 |
flash('Allowed image types are - png, jpg, jpeg')
|
153 |
return redirect(request.url)
|
154 |
|
155 |
-
|
156 |
@app.route('/dbresults')
|
157 |
def dbresults():
|
158 |
"""Fetch all results from MongoDB, show aggregated data, and render in a template."""
|
@@ -185,4 +162,4 @@ def dbresults():
|
|
185 |
|
186 |
|
187 |
if __name__ == '__main__':
|
188 |
-
app.run(debug=True)
|
|
|
88 |
|
89 |
flash('Image successfully uploaded and displayed below')
|
90 |
|
|
|
91 |
try:
|
92 |
# Process the image
|
93 |
img = cv2.imread(temp_file.name)
|
|
|
95 |
img = crop_imgs([img])
|
96 |
img = img.reshape(img.shape[1:]) # Reshape to (height, width, channels)
|
97 |
img = preprocess_imgs([img], (128, 128)) # Resize to (128, 128, 3)
|
98 |
+
|
99 |
# Ensure the input shape matches the model's expectation
|
100 |
img = img[0] # Remove unnecessary extra dimension
|
101 |
img = np.expand_dims(img, axis=0) # Add batch dimension to match (1, 128, 128, 3)
|
102 |
+
|
103 |
# Make prediction
|
104 |
pred = braintumor_model.predict(img)
|
105 |
prediction = 'Tumor Detected' if pred[0][0] >= 0.5 else 'No Tumor Detected'
|
106 |
confidence_score = float(pred[0][0])
|
107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
# Prepare data for MongoDB
|
109 |
result = {
|
110 |
"firstname": firstname,
|
|
|
130 |
flash('Allowed image types are - png, jpg, jpeg')
|
131 |
return redirect(request.url)
|
132 |
|
|
|
133 |
@app.route('/dbresults')
|
134 |
def dbresults():
|
135 |
"""Fetch all results from MongoDB, show aggregated data, and render in a template."""
|
|
|
162 |
|
163 |
|
164 |
if __name__ == '__main__':
|
165 |
+
app.run(debug=True)
|