Accessing /data folder of persistent storage

Hi, I have a pretty dumb question. I set up persistent storage for one of my spaces and the docs said that this is stored on the “/data” folder.

How do I access this folder? How can I see what’s in it and save the data locally via Python?

Thanks,
AJ

hi @indiaj27 ,

Currently, there is no storage/file management via UI. We will be adding this feature in the near future.
If you’re using Gradio you could try to leverage the gr.Files to list and serve the files under a specific folder. Here is an example

import gradio as gr
from pathlib import Path

DATA_PATH = Path("./")  #  Path("/data")
def get_storage():
    files = [
        {
            "orig_name": file.name,
            "name": file.resolve(),
            "size": file.stat().st_size,
            "data": None,
            "is_file": True,
        }
        for file in DATA_PATH.glob("**/*")
        if file.is_file()
    ]
    usage = sum([f['size'] for f in files])
    return files, f"{usage/(1024.0 ** 3):.3f}GB"

with gr.Blocks() as app:
    with gr.Row():
        with gr.Column():
            btn = gr.Button("Run")
        with gr.Column():
            files = gr.Files(label="Files")
            storage = gr.Text(label="Total Usage")
    btn.click(get_storage, inputs=None, outputs=[files, storage], postprocess=False)

# Files that you explicitly allow on allowed_paths 
app.launch(allowed_paths=[str(DATA_PATH)])
1 Like

Hi @radames! Thanks for replying :slight_smile:

I was actually referring more to using Python to programatically access the files, rather than the UI, but that’s good to know for the future!

I’m using Argilla - would you happen to know how to access the files from Python in that case?

Are there any updates to this? I would like to also access files in /data , my current use-case is logging all my app logs to a file for persistent logging and later access

The gradio solution implies that the file would be public? If that is the case that would not be good for my use-case, as I would like logs to remain private