Spaces:
Runtime error
Runtime error
LovnishVerma
commited on
Commit
•
ca99111
1
Parent(s):
2765643
Update app.py
Browse files
app.py
CHANGED
@@ -58,8 +58,15 @@ def preprocess_image(file_path):
|
|
58 |
def binary_decision(confidence):
|
59 |
return 1 if confidence >= 0.5 else 0
|
60 |
|
61 |
-
def predict_braintumor(
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
# Crop and preprocess the grayscale image
|
65 |
img_processed = crop_imgs([img_gray])
|
@@ -85,15 +92,8 @@ def main():
|
|
85 |
# Read the contents of the uploaded file
|
86 |
file_contents = uploaded_file.read()
|
87 |
|
88 |
-
# Save the uploaded file
|
89 |
-
filename = secure_filename(uploaded_file.name)
|
90 |
-
file_path = os.path.join(UPLOAD_FOLDER, filename)
|
91 |
-
|
92 |
-
with open(file_path, "wb") as f:
|
93 |
-
f.write(file_contents)
|
94 |
-
|
95 |
# Make prediction
|
96 |
-
result = predict_braintumor(
|
97 |
|
98 |
# Display prediction
|
99 |
st.subheader("Prediction:")
|
|
|
58 |
def binary_decision(confidence):
|
59 |
return 1 if confidence >= 0.5 else 0
|
60 |
|
61 |
+
def predict_braintumor(file_contents):
|
62 |
+
# Save the uploaded file
|
63 |
+
filename = "temp_image.png"
|
64 |
+
file_path = os.path.join(UPLOAD_FOLDER, filename)
|
65 |
+
|
66 |
+
with open(file_path, "wb") as f:
|
67 |
+
f.write(file_contents)
|
68 |
+
|
69 |
+
img_gray = cv2.imread(file_path, cv2.IMREAD_GRAYSCALE)
|
70 |
|
71 |
# Crop and preprocess the grayscale image
|
72 |
img_processed = crop_imgs([img_gray])
|
|
|
92 |
# Read the contents of the uploaded file
|
93 |
file_contents = uploaded_file.read()
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
# Make prediction
|
96 |
+
result = predict_braintumor(file_contents)
|
97 |
|
98 |
# Display prediction
|
99 |
st.subheader("Prediction:")
|