import os from huggingface_hub import HfApi from dotenv import load_dotenv load_dotenv() REPO_ID = "hisham-cmd/GrowthPanelBackend" HF_TOKEN = os.environ.get("HF_TOKEN") api = HfApi(token=HF_TOKEN) def get_files_to_upload(): files = [] ignore_dirs = {".git", "__pycache__", ".venv", "venv", "env", "node_modules", ".pytest_cache"} ignore_files = {".env"} for root, dirs, files_list in os.walk("."): # Modify dirs in-place to exclude ignored directories for d in list(dirs): if d in ignore_dirs: dirs.remove(d) for f in files_list: if f in ignore_files: continue file_path = os.path.join(root, f) # Remove leading .\ or ./ prefix = f".{os.sep}" if file_path.startswith(prefix): repo_path = file_path[len(prefix):].replace("\\", "/") else: repo_path = file_path.replace("\\", "/") files.append((file_path, repo_path)) return files def upload(): print(f"\n>>> Preparing to upload backend files to: https://huggingface.co/{REPO_ID}") files = get_files_to_upload() print(f"[*] Found {len(files)} files to upload") try: print(f"[*] Creating repository...") api.create_repo(repo_id=REPO_ID, repo_type="space", space_sdk="docker", private=False, exist_ok=True) print(f"[*] Uploading files...") for local_path, repo_path in files: print(f" Uploading: {local_path} -> {repo_path}") with open(local_path, 'rb') as f: api.upload_file( path_or_fileobj=f, path_in_repo=repo_path, repo_id=REPO_ID, repo_type="space", commit_message=f"Upload {repo_path}", ) print("\n" + "="*50) print(f"[OK] SUCCESS!") print(f"[LINK] https://huggingface.co/{REPO_ID}") print("="*50) except Exception as e: print(f"\n[ERROR] {e}") if __name__ == "__main__": upload()