Spaces:
Sleeping
Sleeping
import logging | |
from huggingface_hub import HfApi, SpaceCard | |
def create_space_with_content( | |
api: HfApi, | |
repo_id: str, | |
dataset_id: str, | |
html_file_path: str, | |
plot_file_path: str, | |
space_card: str, | |
token: str, | |
): | |
logging.info(f"Creating space {repo_id}") | |
api.create_repo( | |
repo_id=repo_id, | |
repo_type="space", | |
private=False, | |
exist_ok=True, | |
token=token, | |
space_sdk="static", | |
) | |
SpaceCard(content=space_card.format(dataset_id=dataset_id)).push_to_hub( | |
repo_id=repo_id, repo_type="space", token=token | |
) | |
upload_file(api, html_file_path, "index.html", repo_id, token) | |
upload_file(api, plot_file_path, "static_plot.png", repo_id, token) | |
logging.info("Space creation done") | |
return repo_id | |
def upload_file( | |
api: HfApi, | |
file_path: str, | |
path_in_repo: str, | |
repo_id: str, | |
token: str, | |
repo_type: str = "space", | |
): | |
api.upload_file( | |
path_or_fileobj=file_path, | |
path_in_repo=path_in_repo, | |
repo_type=repo_type, | |
repo_id=repo_id, | |
token=token, | |
) | |