Kalbe-x-Bangkit
commited on
Commit
•
5e28aaf
1
Parent(s):
9b4ee41
Combine detection button into sidebar.
Browse files
app.py
CHANGED
@@ -80,7 +80,7 @@ def draw_bbox(image, bbox):
|
|
80 |
|
81 |
model = load_model()
|
82 |
|
83 |
-
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
84 |
|
85 |
if uploaded_file is not None:
|
86 |
file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
|
@@ -88,33 +88,33 @@ if uploaded_file is not None:
|
|
88 |
|
89 |
st.image(image, caption='Uploaded Image.', use_column_width=True)
|
90 |
|
91 |
-
if st.button('Detect'):
|
92 |
-
st.write("Processing...")
|
93 |
-
input_image = preprocess_image(image)
|
94 |
-
pred_bbox, pred_label, pred_label_confidence = predict(model, input_image)
|
95 |
-
|
96 |
-
# Updated label mapping based on the dataset
|
97 |
-
label_mapping = {
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
}
|
107 |
-
|
108 |
-
if pred_label_confidence < 0.2:
|
109 |
-
|
110 |
-
else:
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
|
119 |
|
120 |
# Utility Functions
|
@@ -469,31 +469,32 @@ if uploaded_file is not None:
|
|
469 |
|
470 |
with col2:
|
471 |
if st.button('Auto Detect'):
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
cv2.putText(image, f"IoU: {iou:.4f}", (x_pos, y_pos), cv2.FONT_HERSHEY_SIMPLEX, font_size, (255, 0, 0), 2)
|
492 |
-
cv2.putText(image, f"Label: {label}", (x_pos, y_pos + 30), cv2.FONT_HERSHEY_SIMPLEX, font_size, (255, 255, 255), 2)
|
493 |
-
|
494 |
-
st.image(image, channels="BGR")
|
495 |
else:
|
496 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
497 |
|
498 |
with col3:
|
499 |
if st.button('Generate Grad-CAM'):
|
|
|
80 |
|
81 |
model = load_model()
|
82 |
|
83 |
+
# uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
84 |
|
85 |
if uploaded_file is not None:
|
86 |
file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
|
|
|
88 |
|
89 |
st.image(image, caption='Uploaded Image.', use_column_width=True)
|
90 |
|
91 |
+
# if st.button('Detect'):
|
92 |
+
# st.write("Processing...")
|
93 |
+
# input_image = preprocess_image(image)
|
94 |
+
# pred_bbox, pred_label, pred_label_confidence = predict(model, input_image)
|
95 |
+
|
96 |
+
# # Updated label mapping based on the dataset
|
97 |
+
# label_mapping = {
|
98 |
+
# 0: 'Atelectasis',
|
99 |
+
# 1: 'Cardiomegaly',
|
100 |
+
# 2: 'Effusion',
|
101 |
+
# 3: 'Infiltrate',
|
102 |
+
# 4: 'Mass',
|
103 |
+
# 5: 'Nodule',
|
104 |
+
# 6: 'Pneumonia',
|
105 |
+
# 7: 'Pneumothorax'
|
106 |
+
# }
|
107 |
+
|
108 |
+
# if pred_label_confidence < 0.2:
|
109 |
+
# st.write("May not detect a disease.")
|
110 |
+
# else:
|
111 |
+
# pred_label_name = label_mapping[pred_label]
|
112 |
+
# st.write(f"Prediction Label: {pred_label_name}")
|
113 |
+
# st.write(f"Prediction Bounding Box: {pred_bbox}")
|
114 |
+
# st.write(f"Prediction Confidence: {pred_label_confidence:.2f}")
|
115 |
+
|
116 |
+
# output_image = draw_bbox(image.copy(), pred_bbox)
|
117 |
+
# st.image(output_image, caption='Detected Image.', use_column_width=True)
|
118 |
|
119 |
|
120 |
# Utility Functions
|
|
|
469 |
|
470 |
with col2:
|
471 |
if st.button('Auto Detect'):
|
472 |
+
st.write("Processing...")
|
473 |
+
input_image = preprocess_image(image)
|
474 |
+
pred_bbox, pred_label, pred_label_confidence = predict(model, input_image)
|
475 |
+
|
476 |
+
# Updated label mapping based on the dataset
|
477 |
+
label_mapping = {
|
478 |
+
0: 'Atelectasis',
|
479 |
+
1: 'Cardiomegaly',
|
480 |
+
2: 'Effusion',
|
481 |
+
3: 'Infiltrate',
|
482 |
+
4: 'Mass',
|
483 |
+
5: 'Nodule',
|
484 |
+
6: 'Pneumonia',
|
485 |
+
7: 'Pneumothorax'
|
486 |
+
}
|
487 |
+
|
488 |
+
if pred_label_confidence < 0.2:
|
489 |
+
st.write("May not detect a disease.")
|
|
|
|
|
|
|
|
|
|
|
490 |
else:
|
491 |
+
pred_label_name = label_mapping[pred_label]
|
492 |
+
st.write(f"Prediction Label: {pred_label_name}")
|
493 |
+
st.write(f"Prediction Bounding Box: {pred_bbox}")
|
494 |
+
st.write(f"Prediction Confidence: {pred_label_confidence:.2f}")
|
495 |
+
|
496 |
+
output_image = draw_bbox(image.copy(), pred_bbox)
|
497 |
+
st.image(output_image, caption='Detected Image.', use_column_width=True)
|
498 |
|
499 |
with col3:
|
500 |
if st.button('Generate Grad-CAM'):
|