demo-crunchybot / gcp.py
Richie-O3's picture
update backend functions
15ca86d verified
raw
history blame contribute delete
No virus
990 Bytes
import os
from pathlib import Path
from datetime import timedelta
from google.cloud import storage
from huggingface_hub import hf_hub_download
from google.cloud.storage import transfer_manager
from dotenv import load_dotenv
load_dotenv()
REPO_HUGGING = os.getenv("REPO_HUGGING")
HUB_TOKEN = os.getenv("HUB_TOKEN")
def download_credentials() -> None:
"""
Downloads the GCP credentials from Hugging Face Hub
"""
assets_dir = 'assets'
credentials_file = os.path.join(assets_dir, "credentials.json")
print(credentials_file)
# Verificar si la carpeta 'assets' existe y crearla si no
os.makedirs(assets_dir, exist_ok=True)
# Verificar si el archivo 'credentials.json' ya existe en la carpeta 'assets'
if not os.path.isfile(credentials_file):
print("No habian credenciales")
hf_hub_download(
repo_id=REPO_HUGGING, repo_type='dataset', filename="credentials.json",
token=HUB_TOKEN, local_dir=assets_dir
)