fpessanha commited on
Commit
7bd2a1d
·
1 Parent(s): e65f31d

Fix: File download

Browse files
Files changed (1) hide show
  1. app.py +24 -21
app.py CHANGED
@@ -255,23 +255,24 @@ def get_audio_duration(file_path):
255
  return audio.info.length # Duration in seconds
256
 
257
  def get_storage(password):
258
- #source: https://discuss.huggingface.co/t/accessing-data-folder-of-persistent-storage/46681/2
259
  if password == password_files:
 
260
  files = [
261
- {
262
- "orig_name": file.name,
263
- "name": file.resolve(),
264
- "size": file.stat().st_size,
265
- "data": None,
266
- "is_file": True,
267
- }
268
- for file in persistent_storage.glob("**/*.csv")
269
- if file.is_file()
270
  ]
271
- usage = sum([f['size'] for f in files])
 
 
 
 
 
 
 
 
 
272
  else:
273
- gr.Warning("Please provide the correct password")
274
- return files, f"{usage/(1024.0 ** 3):.3f}GB"
275
 
276
 
277
  def load_first_example(participant_id, ann_completed, current_index):
@@ -495,15 +496,17 @@ with (gr.Blocks(theme=gr.themes.Soft(), css = css) as demo):
495
  audio_player.play(count_clicks, [n_clicks], [n_clicks])
496
 
497
  with gr.Tab("Access Files"):
 
498
  with gr.Row():
499
- with gr.Column():
500
- password = gr.Textbox(label='Password', interactive = True)
501
- get_files_button = gr.Button("Get Files")
502
-
503
- with gr.Column():
504
- files = gr.Files(label="Files")
505
- storage = gr.Text(label="Total Usage")
506
- get_files_button.click(get_storage, inputs= [password], outputs=[files, storage], postprocess=False)
 
507
 
508
 
509
  demo.launch(allowed_paths = ['/data'])
 
255
  return audio.info.length # Duration in seconds
256
 
257
  def get_storage(password):
258
+ # Check if the password is correct
259
  if password == password_files:
260
+ # Get the list of file paths and calculate the total usage
261
  files = [
262
+ file for file in persistent_storage.glob("**/*.csv") if file.is_file()
 
 
 
 
 
 
 
 
263
  ]
264
+
265
+ # Calculate total usage (in bytes)
266
+ usage = sum([file.stat().st_size for file in files])
267
+
268
+ # Convert file paths to strings for Gradio's File component
269
+ file_paths = [str(file.resolve()) for file in files]
270
+
271
+ # Return the file paths (as strings) and the total usage in GB
272
+ return file_paths, f"{usage / (1024.0 ** 3):.3f}GB"
273
+
274
  else:
275
+ return gr.Warning("Please provide the correct password"), None
 
276
 
277
 
278
  def load_first_example(participant_id, ann_completed, current_index):
 
496
  audio_player.play(count_clicks, [n_clicks], [n_clicks])
497
 
498
  with gr.Tab("Access Files"):
499
+
500
  with gr.Row():
501
+ password = gr.Textbox(label="Enter Password", type="password")
502
+ get_files_button = gr.Button("Get Files")
503
+
504
+ with gr.Column():
505
+ files = gr.File(label="Download Files", file_count="multiple", interactive=True)
506
+ storage = gr.Text(label="Total Usage")
507
+
508
+ get_files_button.click(fn=get_storage, inputs=[password], outputs=[files, storage])
509
+
510
 
511
 
512
  demo.launch(allowed_paths = ['/data'])