Spaces:
Sleeping
Sleeping
Fix: File download
Browse files
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 |
-
#
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
get_files_button.click(get_storage, inputs=
|
|
|
|
| 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'])
|