axxam commited on
Commit
e559262
·
verified ·
1 Parent(s): 7ce81fb

Update upload_suggestions.py

Browse files
Files changed (1) hide show
  1. upload_suggestions.py +11 -16
upload_suggestions.py CHANGED
@@ -1,36 +1,31 @@
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():
9
  token = os.environ.get("HF_TOKEN")
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
30
  )
31
- print("Uploaded suggestions to Hugging Face repo.")
32
  except Exception as e:
33
- print(f"Upload failed: {e}")
34
 
35
  if __name__ == "__main__":
36
- upload()
 
1
  import os
2
  from huggingface_hub import HfApi
3
 
4
+ SOURCE_DB = "/home/libretranslate/suggestions.db"
5
+ DEST_PATH_IN_REPO = "suggestions/suggestions.db"
6
  REPO_ID = "axxam/LibreTranslate_Kabyle"
7
 
8
+ def upload_db():
9
  token = os.environ.get("HF_TOKEN")
10
  if not token:
11
+ print("HF_TOKEN not set skipping upload.")
12
  return
13
+ if not os.path.exists(SOURCE_DB):
14
+ print(f"{SOURCE_DB} not found skipping upload.")
15
  return
16
 
 
 
 
 
 
17
  api = HfApi()
18
  try:
19
  api.upload_file(
20
+ path_or_fileobj=SOURCE_DB,
21
+ path_in_repo=DEST_PATH_IN_REPO,
22
  repo_id=REPO_ID,
23
  repo_type="space",
24
  token=token
25
  )
26
+ print("suggestions.db uploaded successfully.")
27
  except Exception as e:
28
+ print("Upload failed:", e)
29
 
30
  if __name__ == "__main__":
31
+ upload_db()