BounharAbdelaziz commited on
Commit
cf9ff03
·
1 Parent(s): 1656d75

changed update_repo_file: added create_repo()

Browse files
Files changed (1) hide show
  1. utils.py +15 -9
utils.py CHANGED
@@ -458,7 +458,6 @@ def render_fixed_columns(df):
458
  return NotImplementedError
459
 
460
  def update_repo_file(api, repo_id, filename, data):
461
- """Helper function to update a file in the repository"""
462
  # Use the app directory
463
  app_dir = Path("/home/user/app")
464
  temp_file = app_dir / filename
@@ -467,14 +466,21 @@ def update_repo_file(api, repo_id, filename, data):
467
  with open(temp_file, "w") as f:
468
  json.dump(data, f, indent=4)
469
 
470
- # Upload the file back to the repository
471
- api.upload_file(
472
- path_or_fileobj=str(temp_file),
473
- path_in_repo=filename,
474
- repo_id=repo_id,
475
- repo_type="space",
476
- commit_message=f"Update {filename}"
477
- )
 
 
 
 
 
 
 
478
 
479
  def update_darija_one_vs_all_leaderboard(result_df, model_name, target_lang, DIALECT_CONFUSION_LEADERBOARD_FILE="darija_leaderboard_dialect_confusion.json"):
480
  # Initialize Hugging Face API
 
458
  return NotImplementedError
459
 
460
  def update_repo_file(api, repo_id, filename, data):
 
461
  # Use the app directory
462
  app_dir = Path("/home/user/app")
463
  temp_file = app_dir / filename
 
466
  with open(temp_file, "w") as f:
467
  json.dump(data, f, indent=4)
468
 
469
+ try:
470
+ # Try to create the repo if it doesn't exist
471
+ api.create_repo(repo_id, exist_ok=True)
472
+
473
+ # Upload the file back to the repository
474
+ api.upload_file(
475
+ path_or_fileobj=str(temp_file),
476
+ path_in_repo=filename,
477
+ repo_id=repo_id,
478
+ repo_type="model", # Changed back to "model" since it's a regular repo
479
+ commit_message=f"Update {filename}"
480
+ )
481
+ except Exception as e:
482
+ print(f"Error during repository operation: {str(e)}")
483
+ raise
484
 
485
  def update_darija_one_vs_all_leaderboard(result_df, model_name, target_lang, DIALECT_CONFUSION_LEADERBOARD_FILE="darija_leaderboard_dialect_confusion.json"):
486
  # Initialize Hugging Face API