pamixsun commited on
Commit
dfbd972
1 Parent(s): 5bfee0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -11
app.py CHANGED
@@ -30,11 +30,12 @@ def main():
30
  # Instructions
31
  st.markdown("*Hint: click on the top-right corner of an image to enlarge it!*")
32
  # Set the columns
33
- cols = st.beta_columns((1, 1))
34
  cols[0].subheader("Input image")
35
- cols[1].subheader("Class activation map")
 
36
 
37
- # Set the visualization figure
38
  fig, ax = plt.subplots()
39
 
40
  # Sidebar
@@ -45,9 +46,10 @@ def main():
45
  # Choose your own image
46
  uploaded_file = st.sidebar.file_uploader("Upload image", type=['png', 'jpeg', 'jpg'])
47
  if uploaded_file is not None:
48
- # Read the upload image
49
  image = Image.open(uploaded_file).convert('RGB')
50
  image = np.array(image).astype(np.uint8)
 
51
  ax.imshow(image)
52
  ax.axis('off')
53
  cols[0].pyplot(fig)
@@ -55,7 +57,7 @@ def main():
55
  # For newline
56
  st.sidebar.write('\n')
57
 
58
- # Actions
59
  if st.sidebar.button("Analyze image"):
60
 
61
  if uploaded_file is None:
@@ -63,22 +65,34 @@ def main():
63
 
64
  else:
65
  with st.spinner('Loading model...'):
66
- # Load model
67
  model = GlaucomaModel(device=run_device)
68
 
69
  with st.spinner('Analyzing...'):
70
  # Forward the image to the model and get results
71
- disease_idx, cam = model.process(image)
72
 
73
- # Plot the class activation map
74
- ax.imshow(cam)
75
  ax.axis('off')
76
  cols[1].pyplot(fig)
77
 
78
- # Display screening results
 
 
 
 
 
79
  st.subheader(" Screening results:")
80
  st.write('\n')
81
- st.markdown(f"{model.id2label[disease_idx]}")
 
 
 
 
 
 
 
82
 
83
 
84
  if __name__ == '__main__':
 
30
  # Instructions
31
  st.markdown("*Hint: click on the top-right corner of an image to enlarge it!*")
32
  # Set the columns
33
+ cols = st.beta_columns((1, 1, 1))
34
  cols[0].subheader("Input image")
35
+ cols[1].subheader("Optic disc and optic cup")
36
+ cols[2].subheader("Class activation map")
37
 
38
+ # set the visualization figure
39
  fig, ax = plt.subplots()
40
 
41
  # Sidebar
 
46
  # Choose your own image
47
  uploaded_file = st.sidebar.file_uploader("Upload image", type=['png', 'jpeg', 'jpg'])
48
  if uploaded_file is not None:
49
+ # read the upload image
50
  image = Image.open(uploaded_file).convert('RGB')
51
  image = np.array(image).astype(np.uint8)
52
+ # page_idx = 0
53
  ax.imshow(image)
54
  ax.axis('off')
55
  cols[0].pyplot(fig)
 
57
  # For newline
58
  st.sidebar.write('\n')
59
 
60
+ # actions
61
  if st.sidebar.button("Analyze image"):
62
 
63
  if uploaded_file is None:
 
65
 
66
  else:
67
  with st.spinner('Loading model...'):
68
+ # load model
69
  model = GlaucomaModel(device=run_device)
70
 
71
  with st.spinner('Analyzing...'):
72
  # Forward the image to the model and get results
73
+ disease_idx, disc_cup_image, cam, vcdr = model.process(image)
74
 
75
+ # plot the optic disc and optic cup image
76
+ ax.imshow(disc_cup_image)
77
  ax.axis('off')
78
  cols[1].pyplot(fig)
79
 
80
+ # plot the stitched image
81
+ ax.imshow(cam)
82
+ ax.axis('off')
83
+ cols[2].pyplot(fig)
84
+
85
+ # Display JSON
86
  st.subheader(" Screening results:")
87
  st.write('\n')
88
+
89
+ final_results_as_table = f"""
90
+ |Params|Outcomes|
91
+ |---|---|
92
+ |vCDR|{vcdr:.04f}|
93
+ |Category|{model.cls_id2label[disease_idx]}|
94
+ """
95
+ st.markdown(final_results_as_table)
96
 
97
 
98
  if __name__ == '__main__':