Spaces:
Runtime error
Runtime error
More concise scheduler
#2
by
Wauplin
HF Staff
- opened
- scheduler.py +14 -18
scheduler.py
CHANGED
|
@@ -1,7 +1,4 @@
|
|
| 1 |
-
import pathlib
|
| 2 |
-
import shlex
|
| 3 |
import shutil
|
| 4 |
-
import subprocess
|
| 5 |
import tempfile
|
| 6 |
import uuid
|
| 7 |
|
|
@@ -11,21 +8,20 @@ from huggingface_hub import CommitScheduler
|
|
| 11 |
class ZipScheduler(CommitScheduler):
|
| 12 |
def push_to_hub(self):
|
| 13 |
with self.lock:
|
| 14 |
-
|
| 15 |
-
if not paths:
|
| 16 |
return
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
f'tar czf {archive_path} {self.folder_path.name}'),
|
| 21 |
-
cwd=self.folder_path.parent)
|
| 22 |
-
self.api.upload_file(
|
| 23 |
-
repo_id=self.repo_id,
|
| 24 |
-
repo_type=self.repo_type,
|
| 25 |
-
revision=self.revision,
|
| 26 |
-
path_in_repo=archive_path.name,
|
| 27 |
-
path_or_fileobj=archive_path,
|
| 28 |
-
token=self.token,
|
| 29 |
-
)
|
| 30 |
shutil.rmtree(self.folder_path, ignore_errors=True)
|
| 31 |
self.folder_path.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import shutil
|
|
|
|
| 2 |
import tempfile
|
| 3 |
import uuid
|
| 4 |
|
|
|
|
| 8 |
class ZipScheduler(CommitScheduler):
|
| 9 |
def push_to_hub(self):
|
| 10 |
with self.lock:
|
| 11 |
+
if not any(self.folder_path.iterdir()):
|
|
|
|
| 12 |
return
|
| 13 |
+
archive_file = tempfile.NamedTemporaryFile(suffix=".zip")
|
| 14 |
+
archive_name = archive_file.name.split(".")[0] # `make_archive` automatically append `.zip`
|
| 15 |
+
shutil.make_archive(base_name=archive_name, format='zip', root_dir=self.folder_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
shutil.rmtree(self.folder_path, ignore_errors=True)
|
| 17 |
self.folder_path.mkdir(parents=True, exist_ok=True)
|
| 18 |
+
|
| 19 |
+
self.api.upload_file(
|
| 20 |
+
repo_id=self.repo_id,
|
| 21 |
+
repo_type=self.repo_type,
|
| 22 |
+
revision=self.revision,
|
| 23 |
+
path_in_repo=f"{uuid.uuid4()}.zip",
|
| 24 |
+
path_or_fileobj=archive_file.name,
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
archive_file.close()
|