Spaces:
Running
Running
| import os | |
| # Fix httpx NO_PROXY parsing bug on Windows when it contains IPv6 loopback '::1' | |
| for env_var in ["NO_PROXY", "no_proxy"]: | |
| if env_var in os.environ: | |
| os.environ[env_var] = os.environ[env_var].replace(",::1", "").replace("::1", "") | |
| from huggingface_hub import HfApi | |
| # Target repository on Hugging Face | |
| repo_id = "Rendhaputra/BTA_predictive" | |
| # Cek token dari environment variable | |
| token = os.environ.get("HF_TOKEN") | |
| if not token: | |
| print("π Hugging Face Token tidak ditemukan di environment variables.") | |
| token = input("Masukkan Hugging Face Token Anda (dengan akses WRITE): ").strip() | |
| if not token: | |
| print("β Token diperlukan untuk mengunggah berkas ke Hugging Face!") | |
| exit(1) | |
| api = HfApi() | |
| # Upload both XGBoost and Prophet models | |
| files_to_upload = ["xgboost_bta.json", "model_prophet_bta.json"] | |
| for file_name in files_to_upload: | |
| if os.path.exists(file_name): | |
| try: | |
| print(f"π€ Sedang mengunggah '{file_name}' ke repo '{repo_id}'...") | |
| api.upload_file( | |
| path_or_fileobj=file_name, | |
| path_in_repo=file_name, | |
| repo_id=repo_id, | |
| token=token, | |
| repo_type="model" | |
| ) | |
| print(f"β Berkas '{file_name}' berhasil diunggah!") | |
| except Exception as e: | |
| print(f"β Terjadi kesalahan saat mengunggah '{file_name}': {e}") | |
| else: | |
| print(f"β οΈ Berkas '{file_name}' tidak ditemukan, melewati...") | |
| print(f"\nπ Tautan repositori: https://huggingface.co/{repo_id}/tree/main") | |