Plsek commited on
Commit
cc6eac9
·
1 Parent(s): 8ede926

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -19
app.py CHANGED
@@ -125,11 +125,12 @@ def decompose_cavity(pred, th2=0.7, amin=10):
125
 
126
  return cavities
127
 
128
-
129
- def default_threshold():
130
- st.session_state.default = 0.0
131
-
132
-
 
133
 
134
  bordersize = 0.6
135
  _, col, _ = st.columns([bordersize, 3, bordersize])
@@ -161,14 +162,12 @@ if uploaded_file is not None:
161
  col1.subheader("Input image")
162
  col3.subheader("Prediction")
163
  col5.subheader("Decomposed")
164
-
165
- st.session_state.default = 0.0
166
 
167
  with col1:
168
 
169
  # st.markdown("""<style>[data-baseweb="select"] {margin-top: -26px;}</style>""", unsafe_allow_html=True)
170
  max_scale = int(data.shape[0] // 128)
171
- scale = st.selectbox('Scale:',[f"{(i+1)*128}x{(i+1)*128}" for i in range(max_scale)], label_visibility="hidden", on_change=default_threshold)
172
  scale = int(scale.split("x")[0]) // 128
173
 
174
  with col3:
@@ -186,7 +185,7 @@ if uploaded_file is not None:
186
 
187
  with col4:
188
  st.markdown("""<style>[data-baseweb="select"] {margin-top: -36px;}</style>""", unsafe_allow_html=True)
189
- threshold = st.slider("", 0.0, 1.0, st.session_state.default, 0.05, label_visibility="hidden")
190
 
191
  if detect or threshold:
192
  y_pred, wcs = cut_n_predict(data, wcs, scale)
@@ -214,17 +213,12 @@ if uploaded_file is not None:
214
  ccd = CCDData(cav, unit="adu", wcs=wcs)
215
  ccd.write(f"predictions/predicted_{i+1}.fits", overwrite=True)
216
  image_decomposed += (i+1) * np.where(cav > 0, 1, 0)
217
-
218
- shutil.make_archive("predictions.zip", 'zip', "predictions")
219
-
220
- shutil.make_archive("predictions", 'zip', "predictions")
221
-
222
  try: _ = image_decomposed
223
  except: image_decomposed = np.zeros((128,128))
224
  plot_decomposed(image_decomposed)
225
 
226
- with col6:
227
- with open('predictions.zip', 'rb') as f:
228
- res = f.read()
229
- st.markdown("""<style>[data-baseweb="select"] {margin-top: 16px;}</style>""", unsafe_allow_html=True)
230
- download = st.download_button(label="Download", data=res, file_name='prediction.fits', mime="application/octet-stream")
 
125
 
126
  return cavities
127
 
128
+ @st.cache
129
+ def zip_predictions():
130
+ shutil.make_archive("predictions.zip", 'zip', "predictions")
131
+ with open('predictions.zip', 'rb') as f:
132
+ res = f.read()
133
+ return res
134
 
135
  bordersize = 0.6
136
  _, col, _ = st.columns([bordersize, 3, bordersize])
 
162
  col1.subheader("Input image")
163
  col3.subheader("Prediction")
164
  col5.subheader("Decomposed")
 
 
165
 
166
  with col1:
167
 
168
  # st.markdown("""<style>[data-baseweb="select"] {margin-top: -26px;}</style>""", unsafe_allow_html=True)
169
  max_scale = int(data.shape[0] // 128)
170
+ scale = st.selectbox('Scale:',[f"{(i+1)*128}x{(i+1)*128}" for i in range(max_scale)], label_visibility="hidden")
171
  scale = int(scale.split("x")[0]) // 128
172
 
173
  with col3:
 
185
 
186
  with col4:
187
  st.markdown("""<style>[data-baseweb="select"] {margin-top: -36px;}</style>""", unsafe_allow_html=True)
188
+ threshold = st.slider("", 0.0, 1.0, 0.0, 0.05, label_visibility="hidden")
189
 
190
  if detect or threshold:
191
  y_pred, wcs = cut_n_predict(data, wcs, scale)
 
213
  ccd = CCDData(cav, unit="adu", wcs=wcs)
214
  ccd.write(f"predictions/predicted_{i+1}.fits", overwrite=True)
215
  image_decomposed += (i+1) * np.where(cav > 0, 1, 0)
216
+
 
 
 
 
217
  try: _ = image_decomposed
218
  except: image_decomposed = np.zeros((128,128))
219
  plot_decomposed(image_decomposed)
220
 
221
+ with col6:
222
+ res = zip_predictions()
223
+ st.markdown("""<style>[data-baseweb="select"] {margin-top: 16px;}</style>""", unsafe_allow_html=True)
224
+ download = st.download_button(label="Download", data=res, file_name='prediction.fits', mime="application/octet-stream")