Update upload_suggestions.py
Browse files- upload_suggestions.py +10 -4
upload_suggestions.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
import os
|
2 |
from huggingface_hub import HfApi
|
3 |
|
4 |
-
|
|
|
5 |
REPO_ID = "axxam/LibreTranslate_Kabyle"
|
6 |
|
7 |
def upload():
|
@@ -9,15 +10,20 @@ def upload():
|
|
9 |
if not token:
|
10 |
print("HF_TOKEN not set. Skipping upload.")
|
11 |
return
|
12 |
-
if not os.path.exists(
|
13 |
print("No suggestions file found. Nothing to upload.")
|
14 |
return
|
15 |
|
|
|
|
|
|
|
|
|
|
|
16 |
api = HfApi()
|
17 |
try:
|
18 |
api.upload_file(
|
19 |
-
path_or_fileobj=
|
20 |
-
path_in_repo="suggestions/
|
21 |
repo_id=REPO_ID,
|
22 |
repo_type="space",
|
23 |
token=token
|
|
|
1 |
import os
|
2 |
from huggingface_hub import HfApi
|
3 |
|
4 |
+
LOCAL_FILE = "/app/suggestions/suggestions.jsonl"
|
5 |
+
FILENAME = "suggestions.jsonl" # just the filename
|
6 |
REPO_ID = "axxam/LibreTranslate_Kabyle"
|
7 |
|
8 |
def upload():
|
|
|
10 |
if not token:
|
11 |
print("HF_TOKEN not set. Skipping upload.")
|
12 |
return
|
13 |
+
if not os.path.exists(LOCAL_FILE):
|
14 |
print("No suggestions file found. Nothing to upload.")
|
15 |
return
|
16 |
|
17 |
+
# Copy file to a relative path for upload
|
18 |
+
relative_path = f"/tmp/{FILENAME}"
|
19 |
+
os.makedirs("/tmp", exist_ok=True)
|
20 |
+
os.system(f"cp {LOCAL_FILE} {relative_path}")
|
21 |
+
|
22 |
api = HfApi()
|
23 |
try:
|
24 |
api.upload_file(
|
25 |
+
path_or_fileobj=relative_path,
|
26 |
+
path_in_repo=f"suggestions/{FILENAME}",
|
27 |
repo_id=REPO_ID,
|
28 |
repo_type="space",
|
29 |
token=token
|