alrichardbollans commited on
Commit
50baaf9
·
1 Parent(s): 4e43bbf

Add functionality to hide download button

Browse files
Files changed (1) hide show
  1. app.py +22 -3
app.py CHANGED
@@ -30,6 +30,7 @@ app_dir = Path(__file__).parent
30
 
31
  protocol_url = 'https://pgomba.github.io/orchid_protocol/'
32
  discussion_url = 'https://huggingface.co/spaces/TZProject/TZSeedApp/discussions'
 
33
 
34
  # Load the prediction model
35
  predictor = load_model()
@@ -45,7 +46,6 @@ main_app = ui.page_fluid(
45
  ui.input_slider("threshold", "Threshold for Discarding Overlapping Segmentations"
46
  " (ADD a more descriptive label, and explain in text above).", 0, 1.0, 0.8),
47
 
48
-
49
  ui.tags.style("""
50
  .irs.irs--shiny .irs-single { /* square with number */
51
  background-color: #357abd;
@@ -96,7 +96,7 @@ main_app = ui.page_fluid(
96
  ),
97
  ui.input_action_button("analyse", "Analyse", class_="btn-success"),
98
  # ui.input_switch("mask", "Mask", False),
99
- ui.column(4, ui.download_button("download", "Download Results", class_="btn-success")),
100
  width=300
101
 
102
  ),
@@ -123,7 +123,8 @@ app_ui = ui.page_fluid(
123
  "The protocol for taking images compatible with this model is available on ",
124
  ui.a("GitHub", href=protocol_url, target="_blank"),
125
  ". The protocol is available in English, Indonesian, Thai, French, Spanish, Portuguese, Arabic, Mandarin, Malagasy and Japanese.",
126
- " If you have any feedback on the app, please start a discussion on ", ui.a("the HuggingFace space", href=discussion_url, target="_blank"),
 
127
  ". Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, nunc ut laoreet placerat, urna purus rhoncus nisi, "
128
  "vel facilisis magna sem sed tellus."
129
  ),
@@ -136,6 +137,12 @@ app_ui = ui.page_fluid(
136
  # title="App with navbar",
137
  # id="page",
138
  # ),
 
 
 
 
 
 
139
  ui.div(
140
  ui.layout_column_wrap(
141
  ui.output_image("rbg_kew", height='100%', fill=True),
@@ -216,12 +223,15 @@ def server(input, output, session: Session):
216
  return img
217
 
218
  analysis_results = reactive.Value([])
 
219
 
220
  @reactive.Effect
221
  @reactive.event(input.analyse)
222
  async def process_images():
 
223
  files = input.upload()
224
  if not files:
 
225
  return
226
 
227
  results = []
@@ -259,6 +269,7 @@ def server(input, output, session: Session):
259
 
260
  # Update reactive value
261
  analysis_results.set(results)
 
262
 
263
  @output
264
  @render.ui
@@ -267,6 +278,9 @@ def server(input, output, session: Session):
267
  if not results:
268
  return ui.div("No results yet. Upload images and click 'Analyse'.",
269
  class_="text-muted")
 
 
 
270
 
271
  ui_output = []
272
  for idx, r in enumerate(results):
@@ -292,6 +306,11 @@ def server(input, output, session: Session):
292
 
293
  return ui.div(ui_output)
294
 
 
 
 
 
 
295
  @render.download()
296
  def download():
297
  results = analysis_results.get()
 
30
 
31
  protocol_url = 'https://pgomba.github.io/orchid_protocol/'
32
  discussion_url = 'https://huggingface.co/spaces/TZProject/TZSeedApp/discussions'
33
+ acknowledgement_text = "The OrchAId TZ viability dataset used to develop the model was created by the Royal Botanic Gardens, Kew, Silo National des Graines Forestieres, Madagascar, the Ministry of Agriculture, Lands, Housing and Environment, Monsterrat, Instituto de Investigação Agrária de Moçambique, Mozambique, Departmento de Recursos Naturales y Ambientales, Puerto Rico & the National Parks Trust of the Virgin Islands."
34
 
35
  # Load the prediction model
36
  predictor = load_model()
 
46
  ui.input_slider("threshold", "Threshold for Discarding Overlapping Segmentations"
47
  " (ADD a more descriptive label, and explain in text above).", 0, 1.0, 0.8),
48
 
 
49
  ui.tags.style("""
50
  .irs.irs--shiny .irs-single { /* square with number */
51
  background-color: #357abd;
 
96
  ),
97
  ui.input_action_button("analyse", "Analyse", class_="btn-success"),
98
  # ui.input_switch("mask", "Mask", False),
99
+ ui.output_ui("download_ui"),
100
  width=300
101
 
102
  ),
 
123
  "The protocol for taking images compatible with this model is available on ",
124
  ui.a("GitHub", href=protocol_url, target="_blank"),
125
  ". The protocol is available in English, Indonesian, Thai, French, Spanish, Portuguese, Arabic, Mandarin, Malagasy and Japanese.",
126
+ " If you have any feedback on the app, please start a discussion on ",
127
+ ui.a("the HuggingFace space", href=discussion_url, target="_blank"),
128
  ". Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, nunc ut laoreet placerat, urna purus rhoncus nisi, "
129
  "vel facilisis magna sem sed tellus."
130
  ),
 
137
  # title="App with navbar",
138
  # id="page",
139
  # ),
140
+ ui.div(
141
+ ui.p(
142
+ acknowledgement_text
143
+ ),
144
+ class_="acknowledgement-bar"
145
+ ),
146
  ui.div(
147
  ui.layout_column_wrap(
148
  ui.output_image("rbg_kew", height='100%', fill=True),
 
223
  return img
224
 
225
  analysis_results = reactive.Value([])
226
+ is_analyzing = reactive.Value(False) # Track if analysis is in progress
227
 
228
  @reactive.Effect
229
  @reactive.event(input.analyse)
230
  async def process_images():
231
+ is_analyzing.set(True) # Set analyzing flag to True
232
  files = input.upload()
233
  if not files:
234
+ is_analyzing.set(False) # Reset flag if no files
235
  return
236
 
237
  results = []
 
269
 
270
  # Update reactive value
271
  analysis_results.set(results)
272
+ is_analyzing.set(False) # Set analyzing flag to False when done
273
 
274
  @output
275
  @render.ui
 
278
  if not results:
279
  return ui.div("No results yet. Upload images and click 'Analyse'.",
280
  class_="text-muted")
281
+ if is_analyzing.get():
282
+ return ui.div("Analyzing...",
283
+ class_="text-muted")
284
 
285
  ui_output = []
286
  for idx, r in enumerate(results):
 
306
 
307
  return ui.div(ui_output)
308
 
309
+ @render.ui
310
+ def download_ui():
311
+ if analysis_results.get() and not is_analyzing.get():
312
+ return ui.column(4, ui.download_button("download", "Download Results", class_="btn-success"))
313
+
314
  @render.download()
315
  def download():
316
  results = analysis_results.get()