File size: 1,165 Bytes
f38b172
75c6e74
 
681f7d4
 
 
 
 
 
75c6e74
f38b172
75c6e74
 
a832d75
 
 
 
 
f38b172
 
 
a832d75
 
 
 
 
f38b172
 
a832d75
 
 
 
75c6e74
f38b172
 
 
 
 
a832d75
 
75c6e74
a832d75
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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