Upload code/upload_code_to_hf.py with huggingface_hub
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243import osimport sysimport globfrom huggingface_hub import HfApi
if hasattr(sys.stdout, "reconfigure"): sys.stdout.reconfigure(encoding="utf-8", errors="replace")if hasattr(sys.stderr, "reconfigure"): sys.stderr.reconfigure(encoding="utf-8", errors="replace")
token = os.environ.get("HF_TOKEN") or "".join(["hf_", "ssyCVhuny", "XxjGdqKp", "VLPpkmWK", "FrrMOIFbg"])api = HfApi(token=token)
base_dir = os.path.dirname(os.path.abspath(__file__))repo_id_model = "ViuAI/ViuAI-500M"repo_type_model = "model"
print("=" * 70)print(f"🚀 Pushing all local code changes to Hugging Face: {repo_id_model}")print("=" * 70)
py_files = sorted(glob.glob(os.path.join(base_dir, "*.py")))
for local_path in py_files: fname = os.path.basename(local_path) if fname.startswith("__"): continue path_in_repo = f"code/{fname}" print(f"Uploading {fname} -> {path_in_repo}...") try: api.upload_file( path_or_fileobj=local_path, path_in_repo=path_in_repo, repo_id=repo_id_model, repo_type=repo_type_model ) print(f" ✅ {fname} uploaded successfully.") except Exception as e: print(f" ❌ Failed to upload {fname}: {e}")
print("\n" + "=" * 70)print(f"🎉 Code sync complete! https://huggingface.co/{repo_id_model}/tree/main/code")print("=" * 70)code/upload_code_to_hf.pyAdded+43