File size: 1,666 Bytes
7f3c81c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
323f6a7
7f3c81c
 
 
 
 
 
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
from huggingface_hub import HfApi, create_repo
import os

# Try to get token from environment first, then local .env file
token = os.environ.get("HF_TOKEN")
if not token:
    try:
        env_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), ".env")
        if os.path.exists(env_path):
            with open(env_path, "r", encoding="utf-8") as f:
                for line in f:
                    if line.strip().startswith("HF_TOKEN"):
                        parts = line.split("=", 1)
                        if len(parts) > 1:
                            token = parts[1].strip().strip('"').strip("'")
                            break
    except Exception:
        pass

api = HfApi(token=token)

try:
    # Identifier le compte via le token
    user = api.whoami()["name"]
    repo_id = f"{user}/cypher-ai"
    
    print(f"Création de l'Espace : {repo_id}...")
    create_repo(repo_id, token=token, repo_type="space", space_sdk="gradio", exist_ok=True)
    
    print("Ajout du token en tant que Secret...")
    api.add_space_secret(repo_id, "HF_TOKEN", token)
    
    print("Envoi des fichiers (app.py, requirements.txt) vers le cloud Hugging Face...")
    api.upload_folder(
        folder_path="/home/theshellpc/Documents/cypher-ai",
        repo_id=repo_id,
        repo_type="space",
        token=token,
        ignore_patterns=["deploy.py", "venv/**", ".git/**", ".cache/**", "test_*.py", "__pycache__/**", ".env"]
    )
    
    print(f"\n✅ Cypher AI a été déployé avec succès !")
    print(f"Lien de votre Agent : https://huggingface.co/spaces/{repo_id}")
except Exception as e:
    print("Erreur lors du déploiement :", e)