Hide CSV files on Spaces

Is there a way to hide csv files on Spaces to prevent users from being able to download them? I’m aware you can add secrets but that doesn’t seem to cover files?

Hi @bradley6597, here’s a quick trick to get protected files on a public Space

  1. Create a new dataset/model
  2. Use the huggingface_hub library to clone the dataset/model on the path you’re running the script from
  3. Dont forget to add the secret HUGGING_FACE_HUB_TOKEN to your Space secrets so Repository can authenticate token=True, you can also pass the token e.g token=os.environ["HUB_TOKEN"]

example

from huggingface_hub import Repository

repo = Repository(
    local_dir="secret-csvs",
    repo_type="dataset",
    clone_from="radames/secret-csvs",
    token=True
)
repo.git_pull()

Now you can read you files from the secret-csvs folder

1 Like

Thanks @radames!

I ended up following the same principles and used this code instead

from datasets import load_dataset
from huggingface_hub import login

login(token = os.environ['HUB_TOKEN'])
dataset = load_dataset("hugging/face/path")
1 Like

I’m a new fan of HF and I had a similar problem if I wanted to import a utils.py file from private Space. How should I operate it?

Hi @JunchuanYu ! The code snippet shared above @radames should work for your use case as well. But since you only have one file, I think you can use hf_hub_download in your app.py.

Hey @freddyaboulton, how would you then call functions within the file after using hf_hub_download as it’s in the cache?