File size: 1,717 Bytes
8c0b652
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Deploy specific files to HuggingFace Space using the API.
This avoids git history issues with exposed tokens.
"""

import os
from dotenv import load_dotenv
from huggingface_hub import HfApi, upload_file

# Load environment variables
load_dotenv()

def deploy_to_hf_space():
    """Upload essential files to HuggingFace Space."""
    
    hf_token = os.getenv("HF_TOKEN")
    if not hf_token:
        print("❌ HF_TOKEN not found in environment variables")
        return False
    
    space_id = "jeanbaptdzd/linguacustodia-financial-api"
    
    # Initialize HF API
    api = HfApi()
    
    # Files to upload
    files_to_upload = [
        "app.py",
        "app_config.py", 
        "Dockerfile",
        "requirements.txt",
        "docs/README_HF_SPACE.md"
    ]
    
    print(f"πŸš€ Deploying to HuggingFace Space: {space_id}")
    print("=" * 50)
    
    for file_path in files_to_upload:
        try:
            print(f"πŸ“€ Uploading {file_path}...")
            
            api.upload_file(
                path_or_fileobj=file_path,
                path_in_repo=file_path,
                repo_id=space_id,
                repo_type="space",
                token=hf_token
            )
            
            print(f"βœ… {file_path} uploaded successfully")
            
        except Exception as e:
            print(f"❌ Failed to upload {file_path}: {e}")
            return False
    
    print("\n" + "=" * 50)
    print("βœ… All files uploaded successfully!")
    print(f"🌐 Space URL: https://huggingface.co/spaces/{space_id}")
    print("⏳ The Space will rebuild automatically")
    
    return True

if __name__ == "__main__":
    deploy_to_hf_space()