Kalbe-x-Bangkit
commited on
Commit
•
8267387
1
Parent(s):
dd9aae3
Update app.py
Browse files
app.py
CHANGED
@@ -81,45 +81,45 @@ def draw_bbox(image, bbox):
|
|
81 |
|
82 |
# st.title("Chest X-ray Disease Detection")
|
83 |
|
84 |
-
|
85 |
|
86 |
model_detection = load_model_detection()
|
87 |
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
|
124 |
@st.cache_resource
|
125 |
def load_gradcam_model():
|
@@ -509,39 +509,39 @@ if uploaded_file is not None:
|
|
509 |
redirect_button("https://new-ohif-viewer-k7c3gdlxua-et.a.run.app/")
|
510 |
|
511 |
with col2:
|
512 |
-
model_detection = load_model_detection()
|
513 |
-
file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
|
514 |
-
image = cv2.imdecode(file_bytes, 1)
|
515 |
|
516 |
# st.image(image, caption='Uploaded Image.', use_column_width=True)
|
517 |
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
|
543 |
-
|
544 |
-
|
545 |
|
546 |
|
547 |
# file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
|
|
|
81 |
|
82 |
# st.title("Chest X-ray Disease Detection")
|
83 |
|
84 |
+
st.write("Upload a chest X-ray image and click on 'Detect' to find out if there's any disease.")
|
85 |
|
86 |
model_detection = load_model_detection()
|
87 |
|
88 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png", "dcm"])
|
89 |
+
|
90 |
+
if uploaded_file is not None:
|
91 |
+
file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
|
92 |
+
image = cv2.imdecode(file_bytes, 1)
|
93 |
+
|
94 |
+
st.image(image, caption='Uploaded Image.', use_column_width=False, width=320, height=320)
|
95 |
+
|
96 |
+
if st.button('Detect'):
|
97 |
+
st.write("Processing...")
|
98 |
+
input_image = preprocess_image(image)
|
99 |
+
pred_bbox, pred_label, pred_label_confidence = predict(model_detection, input_image)
|
100 |
+
|
101 |
+
# Updated label mapping based on the dataset
|
102 |
+
label_mapping = {
|
103 |
+
0: 'Atelectasis',
|
104 |
+
1: 'Cardiomegaly',
|
105 |
+
2: 'Effusion',
|
106 |
+
3: 'Infiltrate',
|
107 |
+
4: 'Mass',
|
108 |
+
5: 'Nodule',
|
109 |
+
6: 'Pneumonia',
|
110 |
+
7: 'Pneumothorax'
|
111 |
+
}
|
112 |
+
|
113 |
+
if pred_label_confidence < 0.2:
|
114 |
+
st.write("May not detect a disease.")
|
115 |
+
else:
|
116 |
+
pred_label_name = label_mapping[pred_label]
|
117 |
+
st.write(f"Prediction Label: {pred_label_name}")
|
118 |
+
st.write(f"Prediction Bounding Box: {pred_bbox}")
|
119 |
+
st.write(f"Prediction Confidence: {pred_label_confidence:.2f}")
|
120 |
+
|
121 |
+
output_image = draw_bbox(image.copy(), pred_bbox)
|
122 |
+
st.image(output_image, caption='Detected Image.', use_column_width=False, width=320, height=320)
|
123 |
|
124 |
@st.cache_resource
|
125 |
def load_gradcam_model():
|
|
|
509 |
redirect_button("https://new-ohif-viewer-k7c3gdlxua-et.a.run.app/")
|
510 |
|
511 |
with col2:
|
512 |
+
# model_detection = load_model_detection()
|
513 |
+
# file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
|
514 |
+
# image = cv2.imdecode(file_bytes, 1)
|
515 |
|
516 |
# st.image(image, caption='Uploaded Image.', use_column_width=True)
|
517 |
|
518 |
+
st.button('Detect')
|
519 |
+
# st.write("Processing...")
|
520 |
+
# input_image = preprocess_image(image)
|
521 |
+
# pred_bbox, pred_label, pred_label_confidence = predict(model_detection, input_image)
|
522 |
|
523 |
+
# # Updated label mapping based on the dataset
|
524 |
+
# label_mapping = {
|
525 |
+
# 0: 'Atelectasis',
|
526 |
+
# 1: 'Cardiomegaly',
|
527 |
+
# 2: 'Effusion',
|
528 |
+
# 3: 'Infiltrate',
|
529 |
+
# 4: 'Mass',
|
530 |
+
# 5: 'Nodule',
|
531 |
+
# 6: 'Pneumonia',
|
532 |
+
# 7: 'Pneumothorax'
|
533 |
+
# }
|
534 |
|
535 |
+
# if pred_label_confidence < 0.2:
|
536 |
+
# st.write("May not detect a disease.")
|
537 |
+
# else:
|
538 |
+
# pred_label_name = label_mapping[pred_label]
|
539 |
+
# st.write(f"Prediction Label: {pred_label_name}")
|
540 |
+
# st.write(f"Prediction Bounding Box: {pred_bbox}")
|
541 |
+
# st.write(f"Prediction Confidence: {pred_label_confidence:.2f}")
|
542 |
|
543 |
+
# output_image = draw_bbox(image.copy(), pred_bbox)
|
544 |
+
# st.image(output_image, caption='Detected Image.', use_column_width=True)
|
545 |
|
546 |
|
547 |
# file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
|