Spaces:
Running
Running
File size: 968 Bytes
1690cb0 |
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 |
import os
import sys
from huggingface_hub import HfApi
from dotenv import load_dotenv
# Load env
load_dotenv(override=True)
HF_TOKEN = os.getenv("HF_TOKEN")
REPO_ID = "duqing2026/project-show"
if not HF_TOKEN:
print("Error: HF_TOKEN not found.")
sys.exit(1)
api = HfApi(token=HF_TOKEN)
print(f"Force pushing code to Space: {REPO_ID}...")
# Allow patterns: upload everything except exclusions
# Better to explicitly exclude
ignore_patterns = [
".git*",
".env*",
"venv/*",
"hf_project_showcase_data/*",
"__pycache__/*",
"*.pyc",
".DS_Store",
"*.log"
]
try:
api.upload_folder(
folder_path=".",
repo_id=REPO_ID,
repo_type="space",
path_in_repo=".",
commit_message="Force push code via HfApi (Git fallback)",
ignore_patterns=ignore_patterns
)
print("Code pushed successfully via HfApi.")
except Exception as e:
print(f"Failed to push code: {e}")
sys.exit(1)
|