Fix windows implementation of the ParquetScheduler
#5
by
not-lain
- opened
- app_parquet.py +5 -3
app_parquet.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
# Taken from https://huggingface.co/spaces/hysts-samples/save-user-preferences
|
| 2 |
# Credits to @@hysts
|
|
|
|
| 3 |
import datetime
|
| 4 |
import json
|
| 5 |
import shutil
|
|
@@ -135,8 +136,9 @@ class ParquetScheduler(CommitScheduler):
|
|
| 135 |
)
|
| 136 |
|
| 137 |
# Write to parquet file
|
| 138 |
-
archive_file = tempfile.NamedTemporaryFile()
|
| 139 |
pq.write_table(table, archive_file.name)
|
|
|
|
| 140 |
|
| 141 |
# Upload
|
| 142 |
self.api.upload_file(
|
|
@@ -146,10 +148,10 @@ class ParquetScheduler(CommitScheduler):
|
|
| 146 |
path_in_repo=f"{uuid.uuid4()}.parquet",
|
| 147 |
path_or_fileobj=archive_file.name,
|
| 148 |
)
|
| 149 |
-
print(
|
| 150 |
|
| 151 |
# Cleanup
|
| 152 |
-
archive_file.
|
| 153 |
for path in path_to_cleanup:
|
| 154 |
path.unlink(missing_ok=True)
|
| 155 |
|
|
|
|
| 1 |
# Taken from https://huggingface.co/spaces/hysts-samples/save-user-preferences
|
| 2 |
# Credits to @@hysts
|
| 3 |
+
import os
|
| 4 |
import datetime
|
| 5 |
import json
|
| 6 |
import shutil
|
|
|
|
| 136 |
)
|
| 137 |
|
| 138 |
# Write to parquet file
|
| 139 |
+
archive_file = tempfile.NamedTemporaryFile(delete=False)
|
| 140 |
pq.write_table(table, archive_file.name)
|
| 141 |
+
archive_file.close()
|
| 142 |
|
| 143 |
# Upload
|
| 144 |
self.api.upload_file(
|
|
|
|
| 148 |
path_in_repo=f"{uuid.uuid4()}.parquet",
|
| 149 |
path_or_fileobj=archive_file.name,
|
| 150 |
)
|
| 151 |
+
print("Commit completed.")
|
| 152 |
|
| 153 |
# Cleanup
|
| 154 |
+
os.unlink(archive_file.name)
|
| 155 |
for path in path_to_cleanup:
|
| 156 |
path.unlink(missing_ok=True)
|
| 157 |
|