feat(tools): add script to sync README to Hugging Face Hub
Browse filesUploads the local README.hf.md file as README.md to a specified Hugging Face repository. This automates the documentation update process for the model hub.
- tools/sync_hf_readme.py +38 -0
tools/sync_hf_readme.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
from huggingface_hub import HfApi
|
| 4 |
+
|
| 5 |
+
def sync_readme(repo_id=None):
|
| 6 |
+
hf_token = os.getenv("HF_TOKEN")
|
| 7 |
+
if not hf_token:
|
| 8 |
+
print("Error: HF_TOKEN environment variable not set.")
|
| 9 |
+
return
|
| 10 |
+
|
| 11 |
+
repo_id = repo_id or os.getenv("HF_REPO_ID")
|
| 12 |
+
if not repo_id:
|
| 13 |
+
print("Error: HF_REPO_ID environment variable not set and no repo_id provided as argument.")
|
| 14 |
+
print("Usage: python tools/sync_hf_readme.py <org/model>")
|
| 15 |
+
return
|
| 16 |
+
|
| 17 |
+
api = HfApi()
|
| 18 |
+
|
| 19 |
+
local_path = "README.hf.md"
|
| 20 |
+
if not os.path.exists(local_path):
|
| 21 |
+
print(f"Error: {local_path} not found.")
|
| 22 |
+
return
|
| 23 |
+
|
| 24 |
+
print(f"Uploading {local_path} to {repo_id} as README.md...")
|
| 25 |
+
try:
|
| 26 |
+
api.upload_file(
|
| 27 |
+
path_or_fileobj=local_path,
|
| 28 |
+
path_in_repo="README.md",
|
| 29 |
+
repo_id=repo_id,
|
| 30 |
+
token=hf_token
|
| 31 |
+
)
|
| 32 |
+
print("Successfully synced README to Hugging Face!")
|
| 33 |
+
except Exception as e:
|
| 34 |
+
print(f"An error occurred: {e}")
|
| 35 |
+
|
| 36 |
+
if __name__ == "__main__":
|
| 37 |
+
target_repo = sys.argv[1] if len(sys.argv) > 1 else None
|
| 38 |
+
sync_readme(target_repo)
|