File size: 1,090 Bytes
6b38f47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import logging
from huggingface_hub import hf_hub_download

logger = logging.getLogger(__name__)

REPO_ID = "saiteja020/EnergyStock_SAC"
FILENAME = "bess_RL_master_bundle.safetensors"

def sync_hub_models(local_dir: str):
    """
    Downloads the model bundle from Hugging Face Hub if not already present.
    """
    os.makedirs(local_dir, exist_ok=True)
    local_path = os.path.join(local_dir, FILENAME)
    
    if os.path.exists(local_path):
        logger.info(f"Model bundle '{FILENAME}' already exists at {local_dir}")
        return local_path
    
    logger.info(f"Attempting to download '{FILENAME}' from Hub repository '{REPO_ID}'...")
    try:
        downloaded_path = hf_hub_download(
            repo_id=REPO_ID,
            filename=FILENAME,
            local_dir=local_dir,
            local_dir_use_symlinks=False
        )
        logger.info(f"Successfully downloaded model bundle to {downloaded_path}")
        return downloaded_path
    except Exception as e:
        logger.error(f"Failed to download model bundle from HF Hub: {e}")
        return None