Update app.py
Browse files
app.py
CHANGED
@@ -34,7 +34,7 @@ def main():
|
|
34 |
cols[0].subheader("Input image")
|
35 |
cols[1].subheader("Class activation map")
|
36 |
|
37 |
-
#
|
38 |
fig, ax = plt.subplots()
|
39 |
|
40 |
# Sidebar
|
@@ -45,10 +45,9 @@ 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 |
-
#
|
49 |
image = Image.open(uploaded_file).convert('RGB')
|
50 |
image = np.array(image).astype(np.uint8)
|
51 |
-
# page_idx = 0
|
52 |
ax.imshow(image)
|
53 |
ax.axis('off')
|
54 |
cols[0].pyplot(fig)
|
@@ -56,7 +55,7 @@ def main():
|
|
56 |
# For newline
|
57 |
st.sidebar.write('\n')
|
58 |
|
59 |
-
#
|
60 |
if st.sidebar.button("Analyze image"):
|
61 |
|
62 |
if uploaded_file is None:
|
@@ -64,22 +63,19 @@ def main():
|
|
64 |
|
65 |
else:
|
66 |
with st.spinner('Loading model...'):
|
67 |
-
#
|
68 |
model = GlaucomaModel(device=run_device)
|
69 |
|
70 |
with st.spinner('Analyzing...'):
|
71 |
# Forward the image to the model and get results
|
72 |
disease_idx, cam = model.process(image)
|
73 |
-
|
74 |
-
# visualize results
|
75 |
-
# fig, ax = plt.subplots()
|
76 |
|
77 |
-
#
|
78 |
ax.imshow(cam)
|
79 |
ax.axis('off')
|
80 |
cols[1].pyplot(fig)
|
81 |
|
82 |
-
# Display
|
83 |
st.subheader(" Screening results:")
|
84 |
st.write('\n')
|
85 |
st.markdown(f"{model.id2label[disease_idx]}")
|
|
|
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 |
# 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 |
# 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 |
|
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]}")
|