Spaces:
Sleeping
Sleeping
| # download_data.py | |
| import os | |
| from huggingface_hub import hf_hub_download | |
| import warnings | |
| warnings.filterwarnings( | |
| "ignore", | |
| message="The `local_dir_use_symlinks` argument is deprecated" | |
| ) | |
| REPO_ID = "albertoakel/dados_belem" | |
| SUBDIR = "data/process" | |
| BASE_DIR = "/tmp/dados_belem" | |
| os.makedirs(BASE_DIR, exist_ok=True) | |
| def get_data_file(filename: str) -> str: | |
| """ | |
| Garante que o arquivo existe localmente. | |
| Se não existir, baixa do Hugging Face Dataset. | |
| Retorna o caminho LOCAL FINAL do arquivo. | |
| """ | |
| local_path = os.path.join(BASE_DIR, filename) | |
| if not os.path.exists(local_path): | |
| print(f"⬇️ Baixando {filename} do Hugging Face Dataset...") | |
| downloaded_path = hf_hub_download( | |
| repo_id=REPO_ID, | |
| filename=f"{SUBDIR}/{filename}", | |
| repo_type="dataset", | |
| local_dir=BASE_DIR, | |
| local_dir_use_symlinks=False | |
| ) | |
| # garante que o caminho retornado é o que vamos usar | |
| if downloaded_path != local_path: | |
| os.rename(downloaded_path, local_path) | |
| else: | |
| print(f"✅ Usando cache local: {filename}") | |
| return local_path | |