Spaces:
Runtime error
Runtime error
Ray Chen commited on
Commit ·
64d468d
1
Parent(s): 31ffb4a
new: get HF space information from config
Browse filesFiles changed (3)
123456789from typing import Dict, Literal
from model import Config
UserName = Literal["default"]
SPACE_CONFIG: Dict[UserName, Config] = { "default": {"space_name": "example", "space_owner": "jy-raychen"}}1 unmodified line23456786791010111213141516161718192014 unmodified lines353637383937404142431 unmodified lineimport subprocessimport sys
from config import SPACE_CONFIGfrom model import Space
DEFAULT_USER = "jy-raychen"DEFAULT_SPACE_OWNER = "jy-raychen"DEFAULT_SPACE_NAME = "example"
def force_push_to_remote(token, branch_name):def force_push_to_remote(space: Space, token: str, branch_name: str): proc = subprocess.run( [ "git", "push", "--force", f"https://{DEFAULT_USER}:{token}@huggingface.co/spaces/{DEFAULT_SPACE_OWNER}/{DEFAULT_SPACE_NAME}", f"https://{DEFAULT_USER}:{token}@huggingface.co/spaces/{space.owner}/{space.name}", f"{branch_name}:main", ], capture_output=True,14 unmodified lines parser.add_argument("--user_token", required=True) args = parser.parse_args()
space = Space(SPACE_CONFIG["default"])
push_result = force_push_to_remote(args.user_token, args.branch_name) push_result = force_push_to_remote(space, args.user_token, args.branch_name) if not push_result: sys.exit(1) print(push_result)123456789101112131415from typing import TypedDict
class Config(TypedDict): space_name: str space_owner: str
class Space: name: str owner: str
def __init__(self, config: Config): self.name = config["space_name"] self.owner = config["space_owner"].github/tools/config.pyAdded+9
.github/tools/deploy_to_space.py+8-5
.github/tools/model.pyAdded+15