Spaces:
Runtime error
Runtime error
| 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 with content: {repo_id} on file {html_file_path}") | |
| 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 | |
| ) | |
| api.upload_file( | |
| path_or_fileobj=html_file_path, | |
| path_in_repo="index.html", | |
| repo_type="space", | |
| repo_id=repo_id, | |
| token=token, | |
| ) | |
| logging.info(f"Pushing file to hub: {dataset_id} on file {plot_file_path}") | |
| try: | |
| logging.info(f"About to push {plot_file_path} - {dataset_id}") | |
| api.upload_file( | |
| path_or_fileobj=plot_file_path, | |
| path_in_repo="static_plot.png", | |
| repo_id=repo_id, | |
| repo_type="space", | |
| ) | |
| except Exception as e: | |
| logging.info("Failed to push file", e) | |
| raise | |
| logging.info(f"Space creation done") | |
| return repo_id | |