File size: 2,425 Bytes
1d75522
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""Script to download and prepare models for HuggingFace Spaces."""

import os
import asyncio
import logging
from pathlib import Path
from huggingface_hub import HfApi, upload_file
from reasoning.model_manager import ModelManager

# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

async def download_and_prepare_models():
    """Download all models and prepare for Spaces."""
    try:
        # Initialize model manager
        model_dir = os.path.join(os.getcwd(), "models")
        manager = ModelManager(model_dir)
        
        # Create models directory
        os.makedirs(model_dir, exist_ok=True)
        
        # Download all models
        logger.info("Starting model downloads...")
        await manager.initialize_all_models()
        logger.info("All models downloaded successfully!")
        
        return True
        
    except Exception as e:
        logger.error(f"Error downloading models: {e}")
        return False

def upload_to_spaces(space_name: str = "agentic-system-models"):
    """Upload models to HuggingFace Spaces."""
    try:
        api = HfApi()
        model_dir = os.path.join(os.getcwd(), "models")
        
        # Create .gitattributes for LFS
        gitattributes_path = os.path.join(model_dir, ".gitattributes")
        with open(gitattributes_path, "w") as f:
            f.write("*.gguf filter=lfs diff=lfs merge=lfs -text")
        
        # Upload .gitattributes first
        api.upload_file(
            path_or_fileobj=gitattributes_path,
            path_in_repo=".gitattributes",
            repo_id=f"spaces/{space_name}",
            repo_type="space"
        )
        
        # Upload each model file
        for model_file in Path(model_dir).glob("*.gguf"):
            logger.info(f"Uploading {model_file.name}...")
            api.upload_file(
                path_or_fileobj=str(model_file),
                path_in_repo=f"models/{model_file.name}",
                repo_id=f"spaces/{space_name}",
                repo_type="space"
            )
            
        logger.info("All models uploaded to Spaces successfully!")
        return True
        
    except Exception as e:
        logger.error(f"Error uploading to Spaces: {e}")
        return False

if __name__ == "__main__":
    # Download models
    asyncio.run(download_and_prepare_models())
    
    # Upload to Spaces
    upload_to_spaces()