kgauvin603 commited on
Commit
61cb383
·
verified ·
1 Parent(s): eacf9f9

Update train.py

Browse files
Files changed (1) hide show
  1. train.py +4 -6
train.py CHANGED
@@ -76,11 +76,11 @@ y_test_pred = model_pipeline.predict(X_test)
76
 
77
  print("Serializing Model")
78
 
79
- # Save the model in the dataset directory
80
  saved_model_path = os.path.join(dataset_dir, "model.joblib")
81
  joblib.dump(model_pipeline, saved_model_path)
82
 
83
- print(f"Model Serialized and Saved to {saved_model_path}")
84
 
85
  # Get the Hugging Face API token securely from the secret environment variable
86
  api_token = os.getenv('FraudDemoWrite') # Access the secret directly using its name
@@ -98,9 +98,7 @@ repo_url = api.create_repo(repo_id=repo_name, token=api_token, exist_ok=True)
98
  # Initialize the repository
99
  repo = Repository(local_dir="hf_model_repo", clone_from=repo_url, use_auth_token=api_token)
100
 
101
- # Move the model to the repository folder
102
- os.rename(saved_model_path, os.path.join("hf_model_repo", "model.joblib"))
103
 
104
- # Push the model to the Hugging Face Hub
105
- repo.push_to_hub(commit_message="Upload trained model")
106
 
 
76
 
77
  print("Serializing Model")
78
 
79
+ # Save the model directly to the dataset directory
80
  saved_model_path = os.path.join(dataset_dir, "model.joblib")
81
  joblib.dump(model_pipeline, saved_model_path)
82
 
83
+ print(f"Model Serialized and Saved directly to {saved_model_path}")
84
 
85
  # Get the Hugging Face API token securely from the secret environment variable
86
  api_token = os.getenv('FraudDemoWrite') # Access the secret directly using its name
 
98
  # Initialize the repository
99
  repo = Repository(local_dir="hf_model_repo", clone_from=repo_url, use_auth_token=api_token)
100
 
101
+ # Directly push the model file to the Hugging Face Hub from the dataset directory
102
+ repo.push_to_hub(commit_message="Upload trained model", repo_id=repo_name)
103
 
 
 
104