Spaces:
Running on Zero
Running on Zero
File size: 1,575 Bytes
2003ad1 | 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | import os
import sys
try:
from huggingface_hub import HfApi
except ImportError:
import subprocess
subprocess.check_call([sys.executable, "-m", "pip", "install", "huggingface_hub"])
from huggingface_hub import HfApi
token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGINGFACE_HUB_TOKEN")
if not token:
raise RuntimeError("Set HF_TOKEN or HUGGINGFACE_HUB_TOKEN before uploading.")
api = HfApi(token=token)
repo_id = "Pratham0100/BrainBox-Backend"
files_to_upload = [
"app.py",
"requirements.txt",
"Dockerfile",
"pyproject.toml",
"README.md"
]
folders_to_upload = [
"backend",
"src"
]
print("Uploading files to Hugging Face...")
for file in files_to_upload:
if os.path.exists(file):
print(f"Uploading {file}...")
api.upload_file(
path_or_fileobj=file,
path_in_repo=file,
repo_id=repo_id,
repo_type="space",
token=token
)
for folder in folders_to_upload:
if os.path.exists(folder):
print(f"Uploading folder {folder}...")
api.upload_folder(
folder_path=folder,
path_in_repo=folder,
repo_id=repo_id,
repo_type="space",
token=token
)
print("Upload to Hugging Face Spaces completed successfully!")
try:
print("Forcing hardware downgrade to CPU Basic...")
api.request_space_hardware(repo_id=repo_id, hardware="cpu-basic")
print("Hardware downgraded successfully!")
except Exception as e:
print(f"Hardware downgrade failed: {e}")
|