kevinlu4588 commited on
Commit
cc54d2a
·
1 Parent(s): 22120f8

Changing upload.py to accept model path as argument

Browse files
models/ESD-X/esd-kellymckernan_from_kellymckernan-xattn_0-epochs_200.pt DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:68e6e320371cf258ab68976ec33ef9d3cc6def9d0b0a8953266235efa2ce6fd9
3
- size 175884838
 
 
 
 
upload.py CHANGED
@@ -1,7 +1,9 @@
1
- from huggingface_hub import HfApi
2
  import os
3
- from dotenv import load_dotenv
4
  import logging
 
 
 
 
5
  logging.basicConfig(level=logging.DEBUG)
6
 
7
  # Load environment variables from .env file
@@ -9,29 +11,28 @@ load_dotenv()
9
 
10
  # Access Hugging Face API token
11
  hf_access_token = os.getenv("HUGGINGFACE_API_KEY")
12
- print(hf_access_token) # Print to confirm loading, remove in production
13
-
14
- # Base path to your models directory
15
- MODEL_PATH = "/Users/klu/ErasingDiffusionModels-1/models"
16
- repo_id = "ErasureResearch/ErasingDiffusionModels" # Target Hugging Face repository
17
 
 
18
  api = HfApi()
19
 
 
 
 
20
  # Ensure the repository exists
21
  api.create_repo(repo_id, exist_ok=True, token=hf_access_token)
22
 
23
  # List existing files in the repository to avoid overwrites
24
  existing_files = api.list_repo_files(repo_id=repo_id, repo_type="model")
25
 
26
- def upload_model_files(subfolder_path):
27
  for root, _, files in os.walk(subfolder_path):
28
  for file in files:
29
  file_path = os.path.join(root, file)
30
- path_in_repo = os.path.relpath(file_path, MODEL_PATH)
31
 
32
  # Check if the file already exists in the repository
33
  if path_in_repo not in existing_files:
34
- print(f"Uploading {file_path} to {repo_id}...")
35
  api.upload_file(
36
  path_or_fileobj=file_path,
37
  path_in_repo=path_in_repo,
@@ -39,15 +40,24 @@ def upload_model_files(subfolder_path):
39
  repo_type="model",
40
  token=hf_access_token
41
  )
42
- print(f"Successfully uploaded {file_path} to {repo_id}.")
43
  else:
44
- print(f"File {path_in_repo} already exists in {repo_id}, skipping upload.")
45
 
46
  def main():
47
- for subfolder in os.listdir(MODEL_PATH):
48
- subfolder_path = os.path.join(MODEL_PATH, subfolder)
 
 
 
 
 
 
 
 
 
49
  if os.path.isdir(subfolder_path):
50
- upload_model_files(subfolder_path)
51
 
52
  if __name__ == "__main__":
53
  main()
 
 
1
  import os
 
2
  import logging
3
+ from huggingface_hub import HfApi
4
+ from dotenv import load_dotenv
5
+ import argparse
6
+
7
  logging.basicConfig(level=logging.DEBUG)
8
 
9
  # Load environment variables from .env file
 
11
 
12
  # Access Hugging Face API token
13
  hf_access_token = os.getenv("HUGGINGFACE_API_KEY")
 
 
 
 
 
14
 
15
+ # Set up Hugging Face API
16
  api = HfApi()
17
 
18
+ # Repository ID to upload to
19
+ repo_id = "ErasureResearch/ErasingDiffusionModels" # Target Hugging Face repository
20
+
21
  # Ensure the repository exists
22
  api.create_repo(repo_id, exist_ok=True, token=hf_access_token)
23
 
24
  # List existing files in the repository to avoid overwrites
25
  existing_files = api.list_repo_files(repo_id=repo_id, repo_type="model")
26
 
27
+ def upload_model_files(model_path, subfolder_path):
28
  for root, _, files in os.walk(subfolder_path):
29
  for file in files:
30
  file_path = os.path.join(root, file)
31
+ path_in_repo = os.path.relpath(file_path, model_path)
32
 
33
  # Check if the file already exists in the repository
34
  if path_in_repo not in existing_files:
35
+ logging.info(f"Uploading {file_path} to {repo_id}...")
36
  api.upload_file(
37
  path_or_fileobj=file_path,
38
  path_in_repo=path_in_repo,
 
40
  repo_type="model",
41
  token=hf_access_token
42
  )
43
+ logging.info(f"Successfully uploaded {file_path} to {repo_id}.")
44
  else:
45
+ logging.info(f"File {path_in_repo} already exists in {repo_id}, skipping upload.")
46
 
47
  def main():
48
+ # Argument parser for model path
49
+ parser = argparse.ArgumentParser(description="Upload model files to Hugging Face Hub")
50
+ parser.add_argument("model_path", type=str, help="Path to the models directory")
51
+ args = parser.parse_args()
52
+
53
+ # Base path to your models directory
54
+ model_path = args.model_path
55
+
56
+ # Process each subfolder in the specified model path
57
+ for subfolder in os.listdir(model_path):
58
+ subfolder_path = os.path.join(model_path, subfolder)
59
  if os.path.isdir(subfolder_path):
60
+ upload_model_files(model_path, subfolder_path)
61
 
62
  if __name__ == "__main__":
63
  main()