| import os | |
| from huggingface_hub import HfApi | |
| # List of possible locations where suggestions.db might be created | |
| possible_paths = [ | |
| "/app/.local/share/db/suggestions.db", | |
| "/root/.local/share/db/suggestions.db", | |
| "/home/libretranslate/.local/share/db/suggestions.db" | |
| ] | |
| # Find the first existing path | |
| SOURCE_DB = next((p for p in possible_paths if os.path.exists(p)), None) | |
| DEST_PATH_IN_REPO = "suggestions/suggestions.db" | |
| REPO_ID = "axxam/LibreTranslate_Kabyle" | |
| def upload_db(): | |
| token = os.environ.get("HF_TOKEN") | |
| if not token: | |
| print("HF_TOKEN not set β skipping upload.") | |
| return | |
| if not SOURCE_DB: | |
| print("suggestions.db not found in any known location β skipping upload.") | |
| return | |
| api = HfApi() | |
| try: | |
| api.upload_file( | |
| path_or_fileobj=SOURCE_DB, | |
| path_in_repo=DEST_PATH_IN_REPO, | |
| repo_id=REPO_ID, | |
| repo_type="space", | |
| token=token | |
| ) | |
| print(f"suggestions.db uploaded successfully from {SOURCE_DB}") | |
| except Exception as e: | |
| print("Upload failed:", e) | |
| if __name__ == "__main__": | |
| upload_db() | |