derek-thomas HF staff commited on
Commit
9188762
1 Parent(s): 27c16af

Update readme to not use Repository

Browse files
Files changed (1) hide show
  1. utilities/readme_update.py +13 -14
utilities/readme_update.py CHANGED
@@ -27,25 +27,24 @@ def update_dataset_readme(dataset_name: str, subreddit: str, new_rows: int) -> N
27
  # Initialize HfApi
28
  api = HfApi()
29
 
30
- if Path(local_repo_path).exists():
31
- rmtree(local_repo_path)
32
 
33
- # Clone the repository locally
34
- repo = Repository(local_repo_path, clone_from=dataset_name, repo_type='dataset', use_auth_token=hf_token)
35
-
36
- # Read the README file
37
- with open(f"{local_repo_path}/README.md", "r") as file:
38
  old_readme = file.read()
39
 
40
- # Modify the README
41
  new_readme = append_to_readme(subreddit=subreddit, new_rows=new_rows, old_readme=old_readme)
42
 
43
- # Write the updated README back to the repository
44
- with open(f"{local_repo_path}/README.md", "w") as file:
45
- file.write(new_readme)
46
-
47
- # Push the changes
48
- repo.push_to_hub(blocking=True, commit_message=f'Pushing {new_rows} new rows')
 
 
49
 
50
 
51
  def append_to_readme(subreddit: str, new_rows: int, old_readme: str) -> str:
 
27
  # Initialize HfApi
28
  api = HfApi()
29
 
30
+ # Download README file
31
+ readme_path = api.hf_hub_download(repo_id=dataset_name, repo_type="dataset", filename="README.md")
32
 
33
+ # Read it
34
+ with open(readme_path, "r") as file:
 
 
 
35
  old_readme = file.read()
36
 
37
+ # Modify it
38
  new_readme = append_to_readme(subreddit=subreddit, new_rows=new_rows, old_readme=old_readme)
39
 
40
+ # Commit modifications
41
+ api.upload_file(
42
+ path_or_fileobj=new_readme.encode(),
43
+ path_in_repo="README.md",
44
+ repo_id=dataset_name,
45
+ repo_type="dataset",
46
+ commit_message=f'Pushing {new_rows} new rows'
47
+ )
48
 
49
 
50
  def append_to_readme(subreddit: str, new_rows: int, old_readme: str) -> str: