Spaces:
Running
Running
cool commited on
Update upload_suggestions.py
Browse files- upload_suggestions.py +15 -19
upload_suggestions.py
CHANGED
|
@@ -1,25 +1,21 @@
|
|
| 1 |
import os
|
| 2 |
-
import subprocess
|
| 3 |
import hashlib
|
| 4 |
import time
|
| 5 |
from huggingface_hub import HfApi
|
| 6 |
|
| 7 |
-
DEST_PATH_IN_REPO = "suggestions/suggestions.db"
|
| 8 |
REPO_ID = "axxam/LibreTranslate_Kabyle"
|
|
|
|
|
|
|
| 9 |
CHECKSUM_FILE = "/app/.last_suggestions_checksum"
|
| 10 |
-
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 11 |
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
except subprocess.CalledProcessError:
|
| 21 |
-
pass
|
| 22 |
-
print("suggestions.db not found.")
|
| 23 |
return None
|
| 24 |
|
| 25 |
def file_checksum(path):
|
|
@@ -44,7 +40,7 @@ def upload_if_updated():
|
|
| 44 |
print("HF_TOKEN not set — skipping upload.")
|
| 45 |
return
|
| 46 |
|
| 47 |
-
db_path =
|
| 48 |
if not db_path:
|
| 49 |
return
|
| 50 |
|
|
@@ -52,12 +48,12 @@ def upload_if_updated():
|
|
| 52 |
last_checksum = load_last_checksum()
|
| 53 |
|
| 54 |
if current_checksum == last_checksum:
|
| 55 |
-
print("
|
| 56 |
return
|
| 57 |
|
| 58 |
-
print("
|
| 59 |
-
api = HfApi()
|
| 60 |
try:
|
|
|
|
| 61 |
api.upload_file(
|
| 62 |
path_or_fileobj=db_path,
|
| 63 |
path_in_repo=DEST_PATH_IN_REPO,
|
|
@@ -69,7 +65,7 @@ def upload_if_updated():
|
|
| 69 |
save_checksum(current_checksum)
|
| 70 |
print(f"Upload successful at {time.strftime('%Y-%m-%d %H:%M:%S')}")
|
| 71 |
except Exception as e:
|
| 72 |
-
print("Upload failed:
|
| 73 |
|
| 74 |
if __name__ == "__main__":
|
| 75 |
upload_if_updated()
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
import hashlib
|
| 3 |
import time
|
| 4 |
from huggingface_hub import HfApi
|
| 5 |
|
|
|
|
| 6 |
REPO_ID = "axxam/LibreTranslate_Kabyle"
|
| 7 |
+
DEST_PATH_IN_REPO = "suggestions/suggestions.db"
|
| 8 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 9 |
CHECKSUM_FILE = "/app/.last_suggestions_checksum"
|
|
|
|
| 10 |
|
| 11 |
+
def get_suggestions_db_path():
|
| 12 |
+
cwd = os.getcwd()
|
| 13 |
+
print(f"Running in CWD: {cwd}") # Debug line
|
| 14 |
+
db_path = os.path.join(cwd, "db", "suggestions.db")
|
| 15 |
+
if os.path.exists(db_path):
|
| 16 |
+
print(f"Found suggestions.db at {db_path}")
|
| 17 |
+
return db_path
|
| 18 |
+
print(f"suggestions.db not found at expected path: {db_path}")
|
|
|
|
|
|
|
|
|
|
| 19 |
return None
|
| 20 |
|
| 21 |
def file_checksum(path):
|
|
|
|
| 40 |
print("HF_TOKEN not set — skipping upload.")
|
| 41 |
return
|
| 42 |
|
| 43 |
+
db_path = get_suggestions_db_path()
|
| 44 |
if not db_path:
|
| 45 |
return
|
| 46 |
|
|
|
|
| 48 |
last_checksum = load_last_checksum()
|
| 49 |
|
| 50 |
if current_checksum == last_checksum:
|
| 51 |
+
print("suggestions.db unchanged — skipping upload.")
|
| 52 |
return
|
| 53 |
|
| 54 |
+
print("Uploading updated suggestions.db to Hugging Face...")
|
|
|
|
| 55 |
try:
|
| 56 |
+
api = HfApi()
|
| 57 |
api.upload_file(
|
| 58 |
path_or_fileobj=db_path,
|
| 59 |
path_in_repo=DEST_PATH_IN_REPO,
|
|
|
|
| 65 |
save_checksum(current_checksum)
|
| 66 |
print(f"Upload successful at {time.strftime('%Y-%m-%d %H:%M:%S')}")
|
| 67 |
except Exception as e:
|
| 68 |
+
print(f"Upload failed: {e}")
|
| 69 |
|
| 70 |
if __name__ == "__main__":
|
| 71 |
upload_if_updated()
|