Update app.py
Browse files
app.py
CHANGED
@@ -11,8 +11,6 @@ from matplotlib.patches import Rectangle
|
|
11 |
from astropy.io import fits
|
12 |
from astropy.wcs import WCS
|
13 |
from astropy.nddata import Cutout2D, CCDData
|
14 |
-
from astropy.convolution import Gaussian2DKernel as Gauss
|
15 |
-
from astropy.convolution import convolve
|
16 |
|
17 |
# Scikit-learn
|
18 |
from sklearn.cluster import DBSCAN
|
@@ -23,7 +21,6 @@ st.set_option('deprecation.showPyplotGlobalUse', False)
|
|
23 |
st.set_page_config(page_title="Cavity Detection Tool", layout="wide")
|
24 |
|
25 |
# HuggingFace Hub
|
26 |
-
# os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
27 |
from huggingface_hub import from_pretrained_keras
|
28 |
# from tensorflow.keras.models import load_model
|
29 |
|
@@ -49,17 +46,15 @@ def plot_prediction(pred):
|
|
49 |
def plot_decomposed(decomposed):
|
50 |
plt.figure(figsize=(4, 4))
|
51 |
plt.imshow(decomposed, origin="lower")
|
52 |
-
|
53 |
N = int(np.max(decomposed))
|
54 |
for i in range(N):
|
55 |
new = np.where(decomposed == i+1, 1, 0)
|
56 |
x0, y0 = center_of_mass(new)
|
57 |
color = "white" if i < N//2 else "black"
|
58 |
plt.text(y0, x0, f"{i+1}", ha="center", va="center", fontsize=15, color=color)
|
59 |
-
|
60 |
plt.axis('off')
|
61 |
with colC: st.pyplot()
|
62 |
-
|
63 |
# Define function to cut input image and rebin it to 128x128 pixels
|
64 |
def cut(data0, wcs0, scale=1):
|
65 |
shape = data0.shape[0]
|
@@ -138,6 +133,7 @@ def decompose_cavity(pred, fname, th2=0.7, amin=10):
|
|
138 |
|
139 |
return image_decomposed
|
140 |
|
|
|
141 |
@st.cache #_data
|
142 |
def load_file(fname):
|
143 |
with fits.open(fname) as hdul:
|
@@ -145,14 +141,17 @@ def load_file(fname):
|
|
145 |
wcs = WCS(hdul[0].header)
|
146 |
return data, wcs
|
147 |
|
|
|
148 |
@st.cache(allow_output_mutation=True) #_resource
|
149 |
def load_CADET():
|
150 |
model = from_pretrained_keras("Plsek/CADET-v1")
|
151 |
# model = load_model("CADET.hdf5")
|
152 |
return model
|
153 |
|
|
|
154 |
def reset_threshold():
|
155 |
-
del st.session_state["threshold"]
|
|
|
156 |
|
157 |
|
158 |
# Load model
|
@@ -178,7 +177,7 @@ with col:
|
|
178 |
# _, col_1, col_2, col_3, _ = st.columns([bordersize, 2.0, 0.5, 0.5, bordersize])
|
179 |
|
180 |
# with col:
|
181 |
-
uploaded_file = st.file_uploader("Choose a FITS file", type=['fits']
|
182 |
|
183 |
# with col_2:
|
184 |
# st.markdown("### Examples")
|
|
|
11 |
from astropy.io import fits
|
12 |
from astropy.wcs import WCS
|
13 |
from astropy.nddata import Cutout2D, CCDData
|
|
|
|
|
14 |
|
15 |
# Scikit-learn
|
16 |
from sklearn.cluster import DBSCAN
|
|
|
21 |
st.set_page_config(page_title="Cavity Detection Tool", layout="wide")
|
22 |
|
23 |
# HuggingFace Hub
|
|
|
24 |
from huggingface_hub import from_pretrained_keras
|
25 |
# from tensorflow.keras.models import load_model
|
26 |
|
|
|
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):
|
60 |
shape = data0.shape[0]
|
|
|
133 |
|
134 |
return image_decomposed
|
135 |
|
136 |
+
# Define function that loads FITS file and return data & wcs
|
137 |
@st.cache #_data
|
138 |
def load_file(fname):
|
139 |
with fits.open(fname) as hdul:
|
|
|
141 |
wcs = WCS(hdul[0].header)
|
142 |
return data, wcs
|
143 |
|
144 |
+
# Define function to load model
|
145 |
@st.cache(allow_output_mutation=True) #_resource
|
146 |
def load_CADET():
|
147 |
model = from_pretrained_keras("Plsek/CADET-v1")
|
148 |
# model = load_model("CADET.hdf5")
|
149 |
return model
|
150 |
|
151 |
+
|
152 |
def reset_threshold():
|
153 |
+
# del st.session_state["threshold"]
|
154 |
+
st.session_state['threshold'] = 0
|
155 |
|
156 |
|
157 |
# Load model
|
|
|
177 |
# _, col_1, col_2, col_3, _ = st.columns([bordersize, 2.0, 0.5, 0.5, bordersize])
|
178 |
|
179 |
# with col:
|
180 |
+
uploaded_file = st.file_uploader("Choose a FITS file", type=['fits'], on_change=reset_threshold)
|
181 |
|
182 |
# with col_2:
|
183 |
# st.markdown("### Examples")
|