Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -88,20 +88,45 @@ def resultbt():
|
|
88 |
|
89 |
flash('Image successfully uploaded and displayed below')
|
90 |
|
|
|
91 |
try:
|
92 |
# Process the image
|
93 |
img = cv2.imread(temp_file.name)
|
94 |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) # Convert to RGB
|
95 |
img = crop_imgs([img])
|
96 |
-
img = img.reshape(img.shape[1:])
|
97 |
-
img = preprocess_imgs([img], (128, 128)) #
|
98 |
-
|
99 |
-
|
|
|
|
|
|
|
100 |
# Make prediction
|
101 |
pred = braintumor_model.predict(img)
|
102 |
prediction = 'Tumor Detected' if pred[0][0] >= 0.5 else 'No Tumor Detected'
|
103 |
confidence_score = float(pred[0][0])
|
104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
# Prepare data for MongoDB
|
106 |
result = {
|
107 |
"firstname": firstname,
|
|
|
88 |
|
89 |
flash('Image successfully uploaded and displayed below')
|
90 |
|
91 |
+
|
92 |
try:
|
93 |
# Process the image
|
94 |
img = cv2.imread(temp_file.name)
|
95 |
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) # Convert to RGB
|
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,
|