Spaces:
Runtime error
Runtime error
some refactor
Browse files- src/hub.py +20 -22
- src/templates.py +1 -1
src/hub.py
CHANGED
|
@@ -11,7 +11,8 @@ def create_space_with_content(
|
|
| 11 |
space_card: str,
|
| 12 |
token: str,
|
| 13 |
):
|
| 14 |
-
logging.info(f"Creating space
|
|
|
|
| 15 |
api.create_repo(
|
| 16 |
repo_id=repo_id,
|
| 17 |
repo_type="space",
|
|
@@ -20,32 +21,29 @@ def create_space_with_content(
|
|
| 20 |
token=token,
|
| 21 |
space_sdk="static",
|
| 22 |
)
|
| 23 |
-
|
| 24 |
SpaceCard(content=space_card.format(dataset_id=dataset_id)).push_to_hub(
|
| 25 |
repo_id=repo_id, repo_type="space", token=token
|
| 26 |
)
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
api.upload_file(
|
| 29 |
-
path_or_fileobj=
|
| 30 |
-
path_in_repo=
|
| 31 |
-
repo_type=
|
| 32 |
repo_id=repo_id,
|
| 33 |
token=token,
|
| 34 |
)
|
| 35 |
-
|
| 36 |
-
logging.info(f"Pushing file to hub: {dataset_id} on file {plot_file_path}")
|
| 37 |
-
|
| 38 |
-
try:
|
| 39 |
-
logging.info(f"About to push {plot_file_path} - {dataset_id}")
|
| 40 |
-
api.upload_file(
|
| 41 |
-
path_or_fileobj=plot_file_path,
|
| 42 |
-
path_in_repo="static_plot.png",
|
| 43 |
-
repo_id=repo_id,
|
| 44 |
-
repo_type="space",
|
| 45 |
-
)
|
| 46 |
-
except Exception as e:
|
| 47 |
-
logging.info("Failed to push file", e)
|
| 48 |
-
raise
|
| 49 |
-
|
| 50 |
-
logging.info(f"Space creation done")
|
| 51 |
-
return repo_id
|
|
|
|
| 11 |
space_card: str,
|
| 12 |
token: str,
|
| 13 |
):
|
| 14 |
+
logging.info(f"Creating space {repo_id}")
|
| 15 |
+
|
| 16 |
api.create_repo(
|
| 17 |
repo_id=repo_id,
|
| 18 |
repo_type="space",
|
|
|
|
| 21 |
token=token,
|
| 22 |
space_sdk="static",
|
| 23 |
)
|
|
|
|
| 24 |
SpaceCard(content=space_card.format(dataset_id=dataset_id)).push_to_hub(
|
| 25 |
repo_id=repo_id, repo_type="space", token=token
|
| 26 |
)
|
| 27 |
|
| 28 |
+
upload_file(api, html_file_path, "index.html", repo_id, token)
|
| 29 |
+
upload_file(api, plot_file_path, "static_plot.png", repo_id, token)
|
| 30 |
+
|
| 31 |
+
logging.info("Space creation done")
|
| 32 |
+
return repo_id
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def upload_file(
|
| 36 |
+
api: HfApi,
|
| 37 |
+
file_path: str,
|
| 38 |
+
path_in_repo: str,
|
| 39 |
+
repo_id: str,
|
| 40 |
+
token: str,
|
| 41 |
+
repo_type: str = "space",
|
| 42 |
+
):
|
| 43 |
api.upload_file(
|
| 44 |
+
path_or_fileobj=file_path,
|
| 45 |
+
path_in_repo=path_in_repo,
|
| 46 |
+
repo_type=repo_type,
|
| 47 |
repo_id=repo_id,
|
| 48 |
token=token,
|
| 49 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/templates.py
CHANGED
|
@@ -20,7 +20,7 @@ Based on the information about the topic above, please create a short label of t
|
|
| 20 |
[/INST]
|
| 21 |
"""
|
| 22 |
|
| 23 |
-
REPRESENTATION_PROMPT = SYSTEM_PROMPT
|
| 24 |
|
| 25 |
SPACE_REPO_CARD_CONTENT = """
|
| 26 |
---
|
|
|
|
| 20 |
[/INST]
|
| 21 |
"""
|
| 22 |
|
| 23 |
+
REPRESENTATION_PROMPT = f"{SYSTEM_PROMPT}{EXAMPLE_PROMPT}{MAIN_PROMPT}"
|
| 24 |
|
| 25 |
SPACE_REPO_CARD_CONTENT = """
|
| 26 |
---
|