Spaces:
Runtime error
Runtime error
LovnishVerma
commited on
Commit
•
6a8052b
1
Parent(s):
ec81163
Update app.py
Browse files
app.py
CHANGED
@@ -12,18 +12,7 @@ braintumor_model = load_model('models/brain_tumor_binary.h5')
|
|
12 |
# Configuring Streamlit
|
13 |
st.set_page_config(page_title="Brain Tumor Prediction App", page_icon=":brain:")
|
14 |
|
15 |
-
def
|
16 |
-
set_new = []
|
17 |
-
for img in set_name:
|
18 |
-
img = cv2.resize(img, dsize=img_size, interpolation=cv2.INTER_CUBIC)
|
19 |
-
set_new.append(preprocess_input(img))
|
20 |
-
return np.array(set_new)
|
21 |
-
|
22 |
-
# Handle binary decision
|
23 |
-
def binary_decision(confidence):
|
24 |
-
return 1 if confidence >= 0.5 else 0
|
25 |
-
|
26 |
-
def predict_braintumor(img):
|
27 |
# If it's a NumPy array, use it directly
|
28 |
if isinstance(img, np.ndarray):
|
29 |
img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
|
@@ -38,7 +27,19 @@ def predict_braintumor(img):
|
|
38 |
img_gray = cv2.imdecode(nparr, cv2.IMREAD_GRAYSCALE)
|
39 |
|
40 |
# Crop and preprocess the grayscale image
|
41 |
-
img_processed =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
# Make prediction
|
44 |
pred = braintumor_model.predict(img_processed)
|
|
|
12 |
# Configuring Streamlit
|
13 |
st.set_page_config(page_title="Brain Tumor Prediction App", page_icon=":brain:")
|
14 |
|
15 |
+
def preprocess_image(img):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
# If it's a NumPy array, use it directly
|
17 |
if isinstance(img, np.ndarray):
|
18 |
img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
|
|
|
27 |
img_gray = cv2.imdecode(nparr, cv2.IMREAD_GRAYSCALE)
|
28 |
|
29 |
# Crop and preprocess the grayscale image
|
30 |
+
img_processed = cv2.resize(img_gray, (224, 224), interpolation=cv2.INTER_CUBIC)
|
31 |
+
img_processed = preprocess_input(img_processed)
|
32 |
+
img_processed = np.expand_dims(img_processed, axis=0)
|
33 |
+
|
34 |
+
return img_processed
|
35 |
+
|
36 |
+
# Handle binary decision
|
37 |
+
def binary_decision(confidence):
|
38 |
+
return 1 if confidence >= 0.5 else 0
|
39 |
+
|
40 |
+
def predict_braintumor(img):
|
41 |
+
# Preprocess the image
|
42 |
+
img_processed = preprocess_image(img)
|
43 |
|
44 |
# Make prediction
|
45 |
pred = braintumor_model.predict(img_processed)
|