fpessanha commited on
Commit
3cbe45e
·
1 Parent(s): bfe263f

Feat: Save progress

Browse files
Files changed (1) hide show
  1. app.py +20 -6
app.py CHANGED
@@ -214,7 +214,8 @@ total_annotations = len(file_list)
214
  # Initialize an empty DataFrame to store annotations
215
  annotations = pd.DataFrame(columns=['sample_id', 'sentence', 'emotion', 'confidence', 'comments'])
216
  current_index = {"index": 0} # Dictionary to allow modifying inside functions
217
-
 
218
  def get_storage():
219
  #source: https://discuss.huggingface.co/t/accessing-data-folder-of-persistent-storage/46681/2
220
  files = [
@@ -232,6 +233,20 @@ def get_storage():
232
  return files, f"{usage/(1024.0 ** 3):.3f}GB"
233
 
234
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
  def load_example(index):
236
  """Loads the example in row #index from dataframe file_list.
237
  If there are any annotations it will give those values to the annotation dataframe"""
@@ -316,7 +331,7 @@ with (gr.Blocks(theme=gr.themes.Soft(), css = css) as demo):
316
  with gr.Tab("Instructions", elem_id = 'instructions'):
317
  instructions = gr.HTML(intro_html, padding = False)
318
 
319
- with gr.Blocks("Audio examples"):
320
  description = gr.HTML(examples_explanation, padding = False)
321
 
322
  with gr.Accordion(label = "Neutral", open= False):
@@ -340,8 +355,7 @@ with (gr.Blocks(theme=gr.themes.Soft(), css = css) as demo):
340
 
341
  with gr.Tab("Annotation Interface"):
342
 
343
- ann_completed = gr.Number(0, visible=False)
344
- total = gr.Number(total_annotations, visible=False)
345
 
346
  # Row with progress bar
347
  gr.HTML("""
@@ -397,8 +411,8 @@ with (gr.Blocks(theme=gr.themes.Soft(), css = css) as demo):
397
  lets_go.click(None, [], [ann_completed, total], js = js_progress_bar)
398
  lets_go.click(deactivate_participant_id, [participant_id, lets_go], [participant_id, lets_go])
399
  lets_go.click(activate_elements, [emotions, confidence, comments, next_button, previous_button], [emotions, confidence, comments, next_button, previous_button])
400
- lets_go.click(load_example, inputs = [gr.Number(current_index["index"], visible = False)], outputs = [sentence_text, audio_player, emotions, confidence, ann_completed, comments])
401
-
402
  with gr.Tab("Access Files"):
403
  with gr.Row():
404
  with gr.Column():
 
214
  # Initialize an empty DataFrame to store annotations
215
  annotations = pd.DataFrame(columns=['sample_id', 'sentence', 'emotion', 'confidence', 'comments'])
216
  current_index = {"index": 0} # Dictionary to allow modifying inside functions
217
+ ann_completed = gr.Number(0, visible=False)
218
+ total = gr.Number(total_annotations, visible=False)
219
  def get_storage():
220
  #source: https://discuss.huggingface.co/t/accessing-data-folder-of-persistent-storage/46681/2
221
  files = [
 
233
  return files, f"{usage/(1024.0 ** 3):.3f}GB"
234
 
235
 
236
+ def load_first_example(index, participant_id):
237
+ """ Loads and first example and updates index"""
238
+
239
+ path_ann = f'{persistent_storage}/{participant_id}_annotations.csv'
240
+ print(path_ann)
241
+ if os.path.exists(path_ann):
242
+ annotations = pd.read_csv(path_ann, index_col = 0)
243
+ current_index['index'] = len(annotations)
244
+ print('path was found')
245
+ print(annotations)
246
+ ann_completed = len(annotations) - 1
247
+ print(current_index)
248
+ return load_example(current_index["index"])
249
+
250
  def load_example(index):
251
  """Loads the example in row #index from dataframe file_list.
252
  If there are any annotations it will give those values to the annotation dataframe"""
 
331
  with gr.Tab("Instructions", elem_id = 'instructions'):
332
  instructions = gr.HTML(intro_html, padding = False)
333
 
334
+ with gr.Blocks():
335
  description = gr.HTML(examples_explanation, padding = False)
336
 
337
  with gr.Accordion(label = "Neutral", open= False):
 
355
 
356
  with gr.Tab("Annotation Interface"):
357
 
358
+
 
359
 
360
  # Row with progress bar
361
  gr.HTML("""
 
411
  lets_go.click(None, [], [ann_completed, total], js = js_progress_bar)
412
  lets_go.click(deactivate_participant_id, [participant_id, lets_go], [participant_id, lets_go])
413
  lets_go.click(activate_elements, [emotions, confidence, comments, next_button, previous_button], [emotions, confidence, comments, next_button, previous_button])
414
+ lets_go.click(load_first_example, inputs = [gr.Number(current_index["index"], visible = False), participant_id], outputs = [sentence_text, audio_player, emotions, confidence, ann_completed, comments])
415
+
416
  with gr.Tab("Access Files"):
417
  with gr.Row():
418
  with gr.Column():