Kalbe-x-Bangkit commited on
Commit
7f6fd0a
1 Parent(s): da64fb1

Revise file_bytes for detection.

Browse files
Files changed (1) hide show
  1. app.py +31 -28
app.py CHANGED
@@ -86,7 +86,7 @@ model = load_model()
86
  # file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
87
  # image = cv2.imdecode(file_bytes, 1)
88
 
89
- # st.image(image, caption='Uploaded Image.', use_column_width=True)
90
 
91
 
92
  # Utility Functions
@@ -440,33 +440,36 @@ if uploaded_file is not None:
440
  redirect_button("https://new-ohif-viewer-k7c3gdlxua-et.a.run.app/")
441
 
442
  with col2:
443
- if st.button('Auto Detect'):
444
- st.write("Processing...")
445
- input_image = preprocess_image(image)
446
- pred_bbox, pred_label, pred_label_confidence = predict(model, input_image)
447
-
448
- # Updated label mapping based on the dataset
449
- label_mapping = {
450
- 0: 'Atelectasis',
451
- 1: 'Cardiomegaly',
452
- 2: 'Effusion',
453
- 3: 'Infiltrate',
454
- 4: 'Mass',
455
- 5: 'Nodule',
456
- 6: 'Pneumonia',
457
- 7: 'Pneumothorax'
458
- }
459
-
460
- if pred_label_confidence < 0.2:
461
- st.write("May not detect a disease.")
462
- else:
463
- pred_label_name = label_mapping[pred_label]
464
- st.write(f"Prediction Label: {pred_label_name}")
465
- st.write(f"Prediction Bounding Box: {pred_bbox}")
466
- st.write(f"Prediction Confidence: {pred_label_confidence:.2f}")
467
-
468
- output_image = draw_bbox(image.copy(), pred_bbox)
469
- st.image(output_image, caption='Detected Image.', use_column_width=True)
 
 
 
470
 
471
  with col3:
472
  if st.button('Generate Grad-CAM'):
 
86
  # file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
87
  # image = cv2.imdecode(file_bytes, 1)
88
 
89
+ # st.image(image, caption='Uploaded Image.', use_column_width=True)
90
 
91
 
92
  # Utility Functions
 
440
  redirect_button("https://new-ohif-viewer-k7c3gdlxua-et.a.run.app/")
441
 
442
  with col2:
443
+ if uploaded_file is not None:
444
+ file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
445
+ image = cv2.imdecode(file_bytes, 1)
446
+ if st.button('Auto Detect'):
447
+ st.write("Processing...")
448
+ input_image = preprocess_image(image)
449
+ pred_bbox, pred_label, pred_label_confidence = predict(model, input_image)
450
+
451
+ # Updated label mapping based on the dataset
452
+ label_mapping = {
453
+ 0: 'Atelectasis',
454
+ 1: 'Cardiomegaly',
455
+ 2: 'Effusion',
456
+ 3: 'Infiltrate',
457
+ 4: 'Mass',
458
+ 5: 'Nodule',
459
+ 6: 'Pneumonia',
460
+ 7: 'Pneumothorax'
461
+ }
462
+
463
+ if pred_label_confidence < 0.2:
464
+ st.write("May not detect a disease.")
465
+ else:
466
+ pred_label_name = label_mapping[pred_label]
467
+ st.write(f"Prediction Label: {pred_label_name}")
468
+ st.write(f"Prediction Bounding Box: {pred_bbox}")
469
+ st.write(f"Prediction Confidence: {pred_label_confidence:.2f}")
470
+
471
+ output_image = draw_bbox(image.copy(), pred_bbox)
472
+ st.image(output_image, caption='Detected Image.', use_column_width=True)
473
 
474
  with col3:
475
  if st.button('Generate Grad-CAM'):