Update app.py
Browse files
app.py
CHANGED
@@ -27,36 +27,33 @@ from huggingface_hub import from_pretrained_keras
|
|
27 |
|
28 |
# Define function to plot the uploaded image
|
29 |
def plot_image(image, scale):
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
with colA: st.image(image)
|
38 |
|
39 |
# Define function to plot the prediction
|
40 |
def plot_prediction(pred):
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
with colB: st.image(pred)
|
46 |
|
47 |
# Define function to plot the decomposed prediction
|
48 |
def plot_decomposed(decomposed):
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
with colC: st.image(decomposed)
|
60 |
|
61 |
# Define function to cut input image and rebin it to 128x128 pixels
|
62 |
def cut(data0, wcs0, scale=1):
|
@@ -170,12 +167,13 @@ os.system("rm -R -- */")
|
|
170 |
# os.system("mkdir -p predictions")
|
171 |
|
172 |
with col:
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
|
|
179 |
|
180 |
# _, col_1, col_2, col_3, _ = st.columns([bordersize, 2.0, 0.5, 0.5, bordersize])
|
181 |
|
|
|
27 |
|
28 |
# Define function to plot the uploaded image
|
29 |
def plot_image(image, scale):
|
30 |
+
plt.figure(figsize=(4, 4))
|
31 |
+
x0 = image.shape[0] // 2 - scale * 128 / 2
|
32 |
+
plt.imshow(image, origin="lower")
|
33 |
+
plt.gca().add_patch(Rectangle((x0-0.5, x0-0.5), scale*128, scale*128, linewidth=1, edgecolor='w', facecolor='none'))
|
34 |
+
plt.axis('off')
|
35 |
+
plt.tight_layout()
|
36 |
+
with colA: st.pyplot()
|
|
|
37 |
|
38 |
# Define function to plot the prediction
|
39 |
def plot_prediction(pred):
|
40 |
+
plt.figure(figsize=(4, 4))
|
41 |
+
plt.imshow(pred, origin="lower", norm=Normalize(vmin=0, vmax=1))
|
42 |
+
plt.axis('off')
|
43 |
+
with colB: st.pyplot()
|
|
|
44 |
|
45 |
# Define function to plot the decomposed prediction
|
46 |
def plot_decomposed(decomposed):
|
47 |
+
plt.figure(figsize=(4, 4))
|
48 |
+
plt.imshow(decomposed, origin="lower")
|
49 |
+
N = int(np.max(decomposed))
|
50 |
+
for i in range(N):
|
51 |
+
new = np.where(decomposed == i+1, 1, 0)
|
52 |
+
x0, y0 = center_of_mass(new)
|
53 |
+
color = "white" if i < N//2 else "black"
|
54 |
+
plt.text(y0, x0, f"{i+1}", ha="center", va="center", fontsize=15, color=color)
|
55 |
+
plt.axis('off')
|
56 |
+
with colC: st.pyplot()
|
|
|
57 |
|
58 |
# Define function to cut input image and rebin it to 128x128 pixels
|
59 |
def cut(data0, wcs0, scale=1):
|
|
|
167 |
# os.system("mkdir -p predictions")
|
168 |
|
169 |
with col:
|
170 |
+
with st.container:
|
171 |
+
# Create heading and description
|
172 |
+
st.markdown("<h1 align='center'>Cavity Detection Tool</h1>", unsafe_allow_html=True)
|
173 |
+
st.markdown("Cavity Detection Tool (CADET) is a machine learning pipeline trained to detect X-ray cavities from noisy Chandra images of early-type galaxies.")
|
174 |
+
st.markdown("To use this tool: upload your image, select the scale of interest, make a prediction, and decompose it into individual cavities!")
|
175 |
+
st.markdown("Input images should be in units of counts, centred at the galaxy center, and point sources should be filled with surrounding background ([dmfilth](https://cxc.cfa.harvard.edu/ciao/ahelp/dmfilth.html)).")
|
176 |
+
st.markdown("If you use this tool for your research, please cite [Plšek et al. 2023](https://arxiv.org/abs/2304.05457)")
|
177 |
|
178 |
# _, col_1, col_2, col_3, _ = st.columns([bordersize, 2.0, 0.5, 0.5, bordersize])
|
179 |
|