Spaces:
Running
Running
File size: 1,566 Bytes
89065dc | 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
# 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")
|