Spaces:
Running
Running
cool commited on
Create upload_suggestions.py
Browse files- upload_suggestions.py +30 -0
upload_suggestions.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from huggingface_hub import HfApi
|
| 3 |
+
|
| 4 |
+
SUGGESTIONS_FILE = "/app/suggestions/suggestions.jsonl"
|
| 5 |
+
REPO_ID = "axxam/LibreTranslate_Kabyle"
|
| 6 |
+
|
| 7 |
+
def upload():
|
| 8 |
+
token = os.environ.get("HF_TOKEN")
|
| 9 |
+
if not token:
|
| 10 |
+
print("HF_TOKEN not set. Skipping upload.")
|
| 11 |
+
return
|
| 12 |
+
if not os.path.exists(SUGGESTIONS_FILE):
|
| 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=SUGGESTIONS_FILE,
|
| 20 |
+
path_in_repo="suggestions/suggestions.jsonl",
|
| 21 |
+
repo_id=REPO_ID,
|
| 22 |
+
repo_type="space",
|
| 23 |
+
token=token
|
| 24 |
+
)
|
| 25 |
+
print("Uploaded suggestions to Hugging Face repo.")
|
| 26 |
+
except Exception as e:
|
| 27 |
+
print(f"Upload failed: {e}")
|
| 28 |
+
|
| 29 |
+
if __name__ == "__main__":
|
| 30 |
+
upload()
|