Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -70,34 +70,40 @@ def brain_tumor():
|
|
| 70 |
@app.route('/resultbt', methods=['POST'])
|
| 71 |
def resultbt():
|
| 72 |
if request.method == 'POST':
|
| 73 |
-
firstname = request.form['firstname']
|
| 74 |
-
lastname = request.form['lastname']
|
| 75 |
-
email = request.form['email']
|
| 76 |
-
phone = request.form['phone']
|
| 77 |
-
gender = request.form['gender']
|
| 78 |
-
age = request.form['age']
|
| 79 |
file = request.files['file']
|
| 80 |
-
|
| 81 |
if file and allowed_file(file.filename):
|
| 82 |
filename = secure_filename(file.filename)
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
flash('Image successfully uploaded and displayed below')
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
pred = 1
|
| 96 |
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
else:
|
| 99 |
flash('Allowed image types are - png, jpg, jpeg')
|
| 100 |
return redirect(request.url)
|
| 101 |
|
|
|
|
| 102 |
if __name__ == '__main__':
|
| 103 |
app.run(debug=True)
|
|
|
|
| 70 |
@app.route('/resultbt', methods=['POST'])
|
| 71 |
def resultbt():
|
| 72 |
if request.method == 'POST':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
file = request.files['file']
|
|
|
|
| 74 |
if file and allowed_file(file.filename):
|
| 75 |
filename = secure_filename(file.filename)
|
| 76 |
+
filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
| 77 |
+
|
| 78 |
+
# Ensure upload folder exists
|
| 79 |
+
if not os.path.exists(app.config['UPLOAD_FOLDER']):
|
| 80 |
+
os.makedirs(app.config['UPLOAD_FOLDER'])
|
| 81 |
+
|
| 82 |
+
file.save(filepath)
|
| 83 |
flash('Image successfully uploaded and displayed below')
|
| 84 |
|
| 85 |
+
# Load and preprocess image
|
| 86 |
+
try:
|
| 87 |
+
img = cv2.imread(filepath)
|
| 88 |
+
if img is None:
|
| 89 |
+
raise ValueError("Image file is invalid or cannot be read.")
|
| 90 |
|
| 91 |
+
img = crop_imgs([img])
|
| 92 |
+
img = img.reshape(img.shape[1:])
|
| 93 |
+
img = preprocess_imgs([img], (224, 224))
|
| 94 |
+
img = img.reshape(1, 224, 224, 3)
|
|
|
|
| 95 |
|
| 96 |
+
pred = braintumor_model.predict(img)
|
| 97 |
+
pred = 1 if pred >= 0.5 else 0
|
| 98 |
+
|
| 99 |
+
return render_template('resultbt.html', filename=filename, r=pred)
|
| 100 |
+
except Exception as e:
|
| 101 |
+
flash(f"Error processing image: {str(e)}")
|
| 102 |
+
return redirect(request.url)
|
| 103 |
else:
|
| 104 |
flash('Allowed image types are - png, jpg, jpeg')
|
| 105 |
return redirect(request.url)
|
| 106 |
|
| 107 |
+
|
| 108 |
if __name__ == '__main__':
|
| 109 |
app.run(debug=True)
|