Kalbe-x-Bangkit
commited on
Commit
•
8b37898
1
Parent(s):
8be2a5a
Update app.py
Browse files
app.py
CHANGED
@@ -454,6 +454,39 @@ if uploaded_file is not None:
|
|
454 |
img_array = np.uint8(img_array) # Convert to uint8
|
455 |
img = Image.fromarray(img_array)
|
456 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
457 |
col1, col2 = st.columns(2)
|
458 |
# Check the number of dimensions of the image
|
459 |
if img_array.ndim == 3:
|
|
|
454 |
img_array = np.uint8(img_array) # Convert to uint8
|
455 |
img = Image.fromarray(img_array)
|
456 |
|
457 |
+
file_bytes = np.asarray(bytearray(uploaded_detection.read()), dtype=np.uint8)
|
458 |
+
image = cv2.imdecode(file_bytes, 1)
|
459 |
+
|
460 |
+
# st.image(image, caption='Uploaded Image.', use_column_width=True)
|
461 |
+
|
462 |
+
if st.button('Detect'):
|
463 |
+
st.write("Processing...")
|
464 |
+
input_image = preprocess_image(image)
|
465 |
+
pred_bbox, pred_label, pred_label_confidence = predict(model_detection, input_image)
|
466 |
+
|
467 |
+
# Updated label mapping based on the dataset
|
468 |
+
label_mapping = {
|
469 |
+
0: 'Atelectasis',
|
470 |
+
1: 'Cardiomegaly',
|
471 |
+
2: 'Effusion',
|
472 |
+
3: 'Infiltrate',
|
473 |
+
4: 'Mass',
|
474 |
+
5: 'Nodule',
|
475 |
+
6: 'Pneumonia',
|
476 |
+
7: 'Pneumothorax'
|
477 |
+
}
|
478 |
+
|
479 |
+
if pred_label_confidence < 0.2:
|
480 |
+
st.write("May not detect a disease.")
|
481 |
+
else:
|
482 |
+
pred_label_name = label_mapping[pred_label]
|
483 |
+
st.write(f"Prediction Label: {pred_label_name}")
|
484 |
+
st.write(f"Prediction Bounding Box: {pred_bbox}")
|
485 |
+
st.write(f"Prediction Confidence: {pred_label_confidence:.2f}")
|
486 |
+
|
487 |
+
output_image = draw_bbox(image.copy(), pred_bbox)
|
488 |
+
st.image(output_image, caption='Detected Image.', use_column_width=True)
|
489 |
+
|
490 |
col1, col2 = st.columns(2)
|
491 |
# Check the number of dimensions of the image
|
492 |
if img_array.ndim == 3:
|