Kalbe-x-Bangkit commited on
Commit
8a37c3c
1 Parent(s): 2bc7b36

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -36
app.py CHANGED
@@ -85,41 +85,41 @@ def draw_bbox(image, bbox):
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=True)
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=True)
123
 
124
  @st.cache_resource
125
  def load_gradcam_model():
@@ -509,9 +509,44 @@ if uploaded_file is not None:
509
  redirect_button("https://new-ohif-viewer-k7c3gdlxua-et.a.run.app/")
510
 
511
  with col2:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
512
  # file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
513
  # image = cv2.imdecode(file_bytes, 1)
514
- st.button('Auto Detect')
515
  # st.write("Processing...")
516
  # input_image = preprocess_image(image)
517
  # pred_bbox, pred_label, pred_label_confidence = predict(model_detection, input_image)
 
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=True)
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=True)
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
+ if 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)
548
  # image = cv2.imdecode(file_bytes, 1)
549
+ # st.button('Auto Detect')
550
  # st.write("Processing...")
551
  # input_image = preprocess_image(image)
552
  # pred_bbox, pred_label, pred_label_confidence = predict(model_detection, input_image)