Spaces:
Sleeping
Sleeping
Update push_to_hub.py
Browse files- push_to_hub.py +3 -7
push_to_hub.py
CHANGED
@@ -2,34 +2,30 @@ from stable_baselines3 import DQN
|
|
2 |
from huggingface_hub import HfApi, HfFolder, Repository
|
3 |
import os
|
4 |
|
|
|
|
|
5 |
def main():
|
6 |
-
# Define repository details
|
7 |
repo_name = "dqn-tetris"
|
8 |
model_path = "models/dqn_tetris.zip"
|
9 |
model_dir = "models"
|
10 |
|
11 |
-
# Load the trained model
|
12 |
model = DQN.load(model_path)
|
13 |
|
14 |
-
# Initialize Hugging Face API
|
15 |
api = HfApi()
|
16 |
user = api.whoami()["name"]
|
17 |
|
18 |
-
# Create the repository if it doesn't exist
|
19 |
try:
|
20 |
api.create_repo(name=repo_name, repo_type="model", exist_ok=True)
|
21 |
print(f"Repository '{repo_name}' created.")
|
22 |
except Exception as e:
|
23 |
print(f"Repository '{repo_name}' already exists or failed to create: {e}")
|
24 |
|
25 |
-
# Clone the repository locally
|
26 |
repo = Repository(local_dir=repo_name, clone_from=f"{user}/{repo_name}", use_auth_token=True)
|
27 |
|
28 |
-
|
29 |
os.makedirs(repo_name, exist_ok=True)
|
30 |
os.rename(model_path, os.path.join(repo_name, "dqn_tetris.zip"))
|
31 |
|
32 |
-
# Add and commit the model
|
33 |
repo.git_add(auto_lfs_track=True)
|
34 |
repo.git_commit("Add trained DQN Tetris model")
|
35 |
repo.git_push()
|
|
|
2 |
from huggingface_hub import HfApi, HfFolder, Repository
|
3 |
import os
|
4 |
|
5 |
+
|
6 |
+
"""This was used in a prior iteration of the model, not currently used but may be used in a future iteration, will keep as may be needed as I move to the sandtris"""
|
7 |
def main():
|
|
|
8 |
repo_name = "dqn-tetris"
|
9 |
model_path = "models/dqn_tetris.zip"
|
10 |
model_dir = "models"
|
11 |
|
|
|
12 |
model = DQN.load(model_path)
|
13 |
|
|
|
14 |
api = HfApi()
|
15 |
user = api.whoami()["name"]
|
16 |
|
|
|
17 |
try:
|
18 |
api.create_repo(name=repo_name, repo_type="model", exist_ok=True)
|
19 |
print(f"Repository '{repo_name}' created.")
|
20 |
except Exception as e:
|
21 |
print(f"Repository '{repo_name}' already exists or failed to create: {e}")
|
22 |
|
|
|
23 |
repo = Repository(local_dir=repo_name, clone_from=f"{user}/{repo_name}", use_auth_token=True)
|
24 |
|
25 |
+
|
26 |
os.makedirs(repo_name, exist_ok=True)
|
27 |
os.rename(model_path, os.path.join(repo_name, "dqn_tetris.zip"))
|
28 |
|
|
|
29 |
repo.git_add(auto_lfs_track=True)
|
30 |
repo.git_commit("Add trained DQN Tetris model")
|
31 |
repo.git_push()
|