Nicha1234 commited on
Commit
58990ff
·
verified ·
1 Parent(s): 80c7d17

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -0
app.py CHANGED
@@ -27,6 +27,13 @@ st.markdown("""
27
  html, body, .stApp {
28
  overflow-x: hidden !important;
29
  }
 
 
 
 
 
 
 
30
  img {
31
  max-width: 100% !important;
32
  height: auto !important;
@@ -121,6 +128,7 @@ def get_image_from_plot(fig):
121
  buf.seek(0)
122
  return Image.open(buf)
123
 
 
124
  def draw_kspace_diagram():
125
  fig, ax = plt.subplots(figsize=(6, 6))
126
 
@@ -156,6 +164,7 @@ def draw_kspace_diagram():
156
  fig.subplots_adjust(left=0.1, right=0.9, top=0.9, bottom=0.1)
157
  return get_image_from_plot(fig)
158
 
 
159
  def draw_kspace_point(kx, ky, bg_image):
160
  fig, ax = plt.subplots(figsize=(4, 4))
161
  ax.imshow(bg_image, cmap='gray', extent=[-112, 112, -112, 112], vmin=0, vmax=1)
@@ -169,6 +178,7 @@ def draw_kspace_point(kx, ky, bg_image):
169
  fig.subplots_adjust(left=0, right=1, top=1, bottom=0)
170
  return get_image_from_plot(fig)
171
 
 
172
  def draw_wave(kx, ky):
173
  fig, ax = plt.subplots(figsize=(4, 4))
174
  x = np.linspace(-112, 112, 224)
@@ -182,6 +192,7 @@ def draw_wave(kx, ky):
182
  fig.subplots_adjust(left=0, right=1, top=1, bottom=0)
183
  return get_image_from_plot(fig)
184
 
 
185
  def apply_filter(k_data, mode, radius):
186
  Y, X = np.ogrid[:224, :224]
187
  dist = np.sqrt((X - 112)**2 + (Y - 112)**2)
@@ -194,6 +205,7 @@ def apply_filter(k_data, mode, radius):
194
  img = np.fft.fftshift(np.fft.ifft2(np.fft.ifftshift(filtered_k)))
195
  return filtered_k, np.abs(img)
196
 
 
197
  def draw_filtered_kspace(filtered_k):
198
  fig, ax = plt.subplots(figsize=(4, 4))
199
  ax.imshow(format_kspace_display(filtered_k), cmap='gray', vmin=0, vmax=1)
@@ -201,6 +213,7 @@ def draw_filtered_kspace(filtered_k):
201
  fig.subplots_adjust(left=0, right=1, top=1, bottom=0)
202
  return get_image_from_plot(fig)
203
 
 
204
  def draw_mri(mri_result):
205
  fig, ax = plt.subplots(figsize=(4, 4))
206
  if np.max(mri_result) > 0:
@@ -213,6 +226,7 @@ def draw_mri(mri_result):
213
  fig.subplots_adjust(left=0, right=1, top=1, bottom=0)
214
  return get_image_from_plot(fig)
215
 
 
216
  def draw_pulse_sequence(current_step, total_steps):
217
  fig, axes = plt.subplots(4, 1, figsize=(5, 6), sharex=True, gridspec_kw={'height_ratios': [1, 1.5, 1, 1]})
218
  t = np.linspace(0, 10, 1000)
@@ -262,6 +276,7 @@ def draw_pulse_sequence(current_step, total_steps):
262
  fig.subplots_adjust(left=0.2, right=0.95, top=0.95, bottom=0.05, hspace=0.2)
263
  return get_image_from_plot(fig)
264
 
 
265
  def draw_kspace_filling(current_step, total_steps):
266
  fig, ax = plt.subplots(figsize=(5, 6))
267
 
 
27
  html, body, .stApp {
28
  overflow-x: hidden !important;
29
  }
30
+ /* Force scrollbar always visible — this is the primary fix for page jitter */
31
+ html {
32
+ overflow-y: scroll !important;
33
+ }
34
+ body {
35
+ overflow-y: scroll !important;
36
+ }
37
  img {
38
  max-width: 100% !important;
39
  height: auto !important;
 
128
  buf.seek(0)
129
  return Image.open(buf)
130
 
131
+ @st.cache_data
132
  def draw_kspace_diagram():
133
  fig, ax = plt.subplots(figsize=(6, 6))
134
 
 
164
  fig.subplots_adjust(left=0.1, right=0.9, top=0.9, bottom=0.1)
165
  return get_image_from_plot(fig)
166
 
167
+ @st.cache_data
168
  def draw_kspace_point(kx, ky, bg_image):
169
  fig, ax = plt.subplots(figsize=(4, 4))
170
  ax.imshow(bg_image, cmap='gray', extent=[-112, 112, -112, 112], vmin=0, vmax=1)
 
178
  fig.subplots_adjust(left=0, right=1, top=1, bottom=0)
179
  return get_image_from_plot(fig)
180
 
181
+ @st.cache_data
182
  def draw_wave(kx, ky):
183
  fig, ax = plt.subplots(figsize=(4, 4))
184
  x = np.linspace(-112, 112, 224)
 
192
  fig.subplots_adjust(left=0, right=1, top=1, bottom=0)
193
  return get_image_from_plot(fig)
194
 
195
+ @st.cache_data
196
  def apply_filter(k_data, mode, radius):
197
  Y, X = np.ogrid[:224, :224]
198
  dist = np.sqrt((X - 112)**2 + (Y - 112)**2)
 
205
  img = np.fft.fftshift(np.fft.ifft2(np.fft.ifftshift(filtered_k)))
206
  return filtered_k, np.abs(img)
207
 
208
+ @st.cache_data
209
  def draw_filtered_kspace(filtered_k):
210
  fig, ax = plt.subplots(figsize=(4, 4))
211
  ax.imshow(format_kspace_display(filtered_k), cmap='gray', vmin=0, vmax=1)
 
213
  fig.subplots_adjust(left=0, right=1, top=1, bottom=0)
214
  return get_image_from_plot(fig)
215
 
216
+ @st.cache_data
217
  def draw_mri(mri_result):
218
  fig, ax = plt.subplots(figsize=(4, 4))
219
  if np.max(mri_result) > 0:
 
226
  fig.subplots_adjust(left=0, right=1, top=1, bottom=0)
227
  return get_image_from_plot(fig)
228
 
229
+ @st.cache_data
230
  def draw_pulse_sequence(current_step, total_steps):
231
  fig, axes = plt.subplots(4, 1, figsize=(5, 6), sharex=True, gridspec_kw={'height_ratios': [1, 1.5, 1, 1]})
232
  t = np.linspace(0, 10, 1000)
 
276
  fig.subplots_adjust(left=0.2, right=0.95, top=0.95, bottom=0.05, hspace=0.2)
277
  return get_image_from_plot(fig)
278
 
279
+ @st.cache_data
280
  def draw_kspace_filling(current_step, total_steps):
281
  fig, ax = plt.subplots(figsize=(5, 6))
282