Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -87,48 +87,6 @@ def draw_bbox(image, bbox):
|
|
| 87 |
|
| 88 |
st.title("AI INTEGRATION FOR CHEST X-RAY")
|
| 89 |
|
| 90 |
-
st.header("Chest X-ray Disease Detection")
|
| 91 |
-
|
| 92 |
-
st.write("Upload a chest X-ray image and click on 'Detect' to find out if there's any disease.")
|
| 93 |
-
|
| 94 |
-
model_detection = load_model_detection()
|
| 95 |
-
|
| 96 |
-
# uploaded_file = st.sidebar.file_uploader("Choose an image...", type=["jpg", "jpeg", "png", "dcm"])
|
| 97 |
-
|
| 98 |
-
if uploaded_detection is not None:
|
| 99 |
-
file_bytes = np.asarray(bytearray(uploaded_detection.read()), dtype=np.uint8)
|
| 100 |
-
image = cv2.imdecode(file_bytes, 1)
|
| 101 |
-
|
| 102 |
-
# st.image(image, caption='Uploaded Image.', use_column_width=True)
|
| 103 |
-
|
| 104 |
-
if st.button('Detect'):
|
| 105 |
-
st.write("Processing...")
|
| 106 |
-
input_image = preprocess_image(image)
|
| 107 |
-
pred_bbox, pred_label, pred_label_confidence = predict(model_detection, input_image)
|
| 108 |
-
|
| 109 |
-
# Updated label mapping based on the dataset
|
| 110 |
-
label_mapping = {
|
| 111 |
-
0: 'Atelectasis',
|
| 112 |
-
1: 'Cardiomegaly',
|
| 113 |
-
2: 'Effusion',
|
| 114 |
-
3: 'Infiltrate',
|
| 115 |
-
4: 'Mass',
|
| 116 |
-
5: 'Nodule',
|
| 117 |
-
6: 'Pneumonia',
|
| 118 |
-
7: 'Pneumothorax'
|
| 119 |
-
}
|
| 120 |
-
|
| 121 |
-
if pred_label_confidence < 0.2:
|
| 122 |
-
st.write("May not detect a disease.")
|
| 123 |
-
else:
|
| 124 |
-
pred_label_name = label_mapping[pred_label]
|
| 125 |
-
st.write(f"Prediction Label: {pred_label_name}")
|
| 126 |
-
st.write(f"Prediction Bounding Box: {pred_bbox}")
|
| 127 |
-
st.write(f"Prediction Confidence: {pred_label_confidence:.2f}")
|
| 128 |
-
|
| 129 |
-
output_image = draw_bbox(image.copy(), pred_bbox)
|
| 130 |
-
st.image(output_image, caption='Detected Image.', use_column_width=True)
|
| 131 |
-
|
| 132 |
@st.cache_resource
|
| 133 |
def load_gradcam_model():
|
| 134 |
model = keras.models.load_model('./model_renamed.h5', compile=False)
|
|
@@ -629,4 +587,46 @@ if uploaded_file is not None:
|
|
| 629 |
try:
|
| 630 |
compute_gradcam(model_gradcam, uploaded_file)
|
| 631 |
except Exception as e:
|
| 632 |
-
st.error(f"Error generating Grad-CAM: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
st.title("AI INTEGRATION FOR CHEST X-RAY")
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
@st.cache_resource
|
| 91 |
def load_gradcam_model():
|
| 92 |
model = keras.models.load_model('./model_renamed.h5', compile=False)
|
|
|
|
| 587 |
try:
|
| 588 |
compute_gradcam(model_gradcam, uploaded_file)
|
| 589 |
except Exception as e:
|
| 590 |
+
st.error(f"Error generating Grad-CAM: {e}")
|
| 591 |
+
|
| 592 |
+
st.header("Chest X-ray Disease Detection")
|
| 593 |
+
|
| 594 |
+
st.write("Upload a chest X-ray image and click on 'Detect' to find out if there's any disease.")
|
| 595 |
+
|
| 596 |
+
model_detection = load_model_detection()
|
| 597 |
+
|
| 598 |
+
# uploaded_file = st.sidebar.file_uploader("Choose an image...", type=["jpg", "jpeg", "png", "dcm"])
|
| 599 |
+
|
| 600 |
+
if uploaded_detection is not None:
|
| 601 |
+
file_bytes = np.asarray(bytearray(uploaded_detection.read()), dtype=np.uint8)
|
| 602 |
+
image = cv2.imdecode(file_bytes, 1)
|
| 603 |
+
|
| 604 |
+
# st.image(image, caption='Uploaded Image.', use_column_width=True)
|
| 605 |
+
|
| 606 |
+
if st.button('Detect'):
|
| 607 |
+
st.write("Processing...")
|
| 608 |
+
input_image = preprocess_image(image)
|
| 609 |
+
pred_bbox, pred_label, pred_label_confidence = predict(model_detection, input_image)
|
| 610 |
+
|
| 611 |
+
# Updated label mapping based on the dataset
|
| 612 |
+
label_mapping = {
|
| 613 |
+
0: 'Atelectasis',
|
| 614 |
+
1: 'Cardiomegaly',
|
| 615 |
+
2: 'Effusion',
|
| 616 |
+
3: 'Infiltrate',
|
| 617 |
+
4: 'Mass',
|
| 618 |
+
5: 'Nodule',
|
| 619 |
+
6: 'Pneumonia',
|
| 620 |
+
7: 'Pneumothorax'
|
| 621 |
+
}
|
| 622 |
+
|
| 623 |
+
if pred_label_confidence < 0.2:
|
| 624 |
+
st.write("May not detect a disease.")
|
| 625 |
+
else:
|
| 626 |
+
pred_label_name = label_mapping[pred_label]
|
| 627 |
+
st.write(f"Prediction Label: {pred_label_name}")
|
| 628 |
+
st.write(f"Prediction Bounding Box: {pred_bbox}")
|
| 629 |
+
st.write(f"Prediction Confidence: {pred_label_confidence:.2f}")
|
| 630 |
+
|
| 631 |
+
output_image = draw_bbox(image.copy(), pred_bbox)
|
| 632 |
+
st.image(output_image, caption='Detected Image.', use_column_width=True)
|