Spaces:
Sleeping
Sleeping
Feat: Add persistent storage
Browse files
app.py
CHANGED
|
@@ -215,6 +215,22 @@ total_annotations = len(file_list)
|
|
| 215 |
annotations = pd.DataFrame(columns=['sample_id', 'sentence', 'emotion', 'confidence', 'comments'])
|
| 216 |
current_index = {"index": 0} # Dictionary to allow modifying inside functions
|
| 217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
|
| 219 |
def load_example(index):
|
| 220 |
"""Loads the example in row #index from dataframe file_list.
|
|
@@ -383,6 +399,15 @@ with (gr.Blocks(theme=gr.themes.Soft(), css = css) as demo):
|
|
| 383 |
lets_go.click(activate_elements, [emotions, confidence, comments, next_button, previous_button], [emotions, confidence, comments, next_button, previous_button])
|
| 384 |
lets_go.click(load_example, inputs = [gr.Number(current_index["index"], visible = False)], outputs = [sentence_text, audio_player, emotions, confidence, ann_completed, comments])
|
| 385 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 386 |
|
| 387 |
demo.launch()
|
| 388 |
|
|
|
|
| 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 = [
|
| 221 |
+
{
|
| 222 |
+
"orig_name": file.name,
|
| 223 |
+
"name": file.resolve(),
|
| 224 |
+
"size": file.stat().st_size,
|
| 225 |
+
"data": None,
|
| 226 |
+
"is_file": True,
|
| 227 |
+
}
|
| 228 |
+
for file in persistent_storage.glob("**/*")
|
| 229 |
+
if file.is_file()
|
| 230 |
+
]
|
| 231 |
+
usage = sum([f['size'] for f in files])
|
| 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.
|
|
|
|
| 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():
|
| 405 |
+
btn = gr.Button("Run")
|
| 406 |
+
with gr.Column():
|
| 407 |
+
files = gr.Files(label="Files")
|
| 408 |
+
storage = gr.Text(label="Total Usage")
|
| 409 |
+
btn.click(get_storage, inputs=None, outputs=[files, storage], postprocess=False)
|
| 410 |
+
|
| 411 |
|
| 412 |
demo.launch()
|
| 413 |
|