kevinlu4588 commited on
Commit
b8bfc2b
·
1 Parent(s): c371153

Testing upload script

Browse files
Pipfile CHANGED
@@ -12,6 +12,8 @@ transformers = "*"
12
  torch = "*"
13
  diffusers = "*"
14
  peft = "*"
 
 
15
 
16
  [dev-packages]
17
 
 
12
  torch = "*"
13
  diffusers = "*"
14
  peft = "*"
15
+ huggingface-hub = "*"
16
+ python-dotenv = "*"
17
 
18
  [dev-packages]
19
 
Pipfile.lock CHANGED
@@ -1,7 +1,7 @@
1
  {
2
  "_meta": {
3
  "hash": {
4
- "sha256": "c4efec9481152ce6f9599932fcd2ea1a68f264c46a099862473a4cbc56ae87ab"
5
  },
6
  "pipfile-spec": 6,
7
  "requires": {
@@ -174,6 +174,7 @@
174
  "sha256:414c0d9b769eecc86c70f9d939d0f48bb28e8461dd1130021542eff0212db890",
175
  "sha256:5927a8fc64ae68859cd954b7cc29d1c8390a5e15caba6d3d349c973be8fdacf3"
176
  ],
 
177
  "markers": "python_full_version >= '3.8.0'",
178
  "version": "==0.26.1"
179
  },
@@ -522,6 +523,15 @@
522
  "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
523
  "version": "==2.9.0.post0"
524
  },
 
 
 
 
 
 
 
 
 
525
  "pytz": {
526
  "hashes": [
527
  "sha256:2aa355083c50a0f93fa581709deac0c9ad65cca8a9e9beac660adcbd493c798a",
@@ -813,6 +823,14 @@
813
  "markers": "python_version >= '3.7'",
814
  "version": "==0.4.5"
815
  },
 
 
 
 
 
 
 
 
816
  "six": {
817
  "hashes": [
818
  "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926",
 
1
  {
2
  "_meta": {
3
  "hash": {
4
+ "sha256": "57e3bd5688f1054cbc1ce950e6dcc4d8ed73eee2d2c72c93c6c2bcd83fd1ac09"
5
  },
6
  "pipfile-spec": 6,
7
  "requires": {
 
174
  "sha256:414c0d9b769eecc86c70f9d939d0f48bb28e8461dd1130021542eff0212db890",
175
  "sha256:5927a8fc64ae68859cd954b7cc29d1c8390a5e15caba6d3d349c973be8fdacf3"
176
  ],
177
+ "index": "pypi",
178
  "markers": "python_full_version >= '3.8.0'",
179
  "version": "==0.26.1"
180
  },
 
523
  "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
524
  "version": "==2.9.0.post0"
525
  },
526
+ "python-dotenv": {
527
+ "hashes": [
528
+ "sha256:e324ee90a023d808f1959c46bcbc04446a10ced277783dc6ee09987c37ec10ca",
529
+ "sha256:f7b63ef50f1b690dddf550d03497b66d609393b40b564ed0d674909a68ebf16a"
530
+ ],
531
+ "index": "pypi",
532
+ "markers": "python_version >= '3.8'",
533
+ "version": "==1.0.1"
534
+ },
535
  "pytz": {
536
  "hashes": [
537
  "sha256:2aa355083c50a0f93fa581709deac0c9ad65cca8a9e9beac660adcbd493c798a",
 
823
  "markers": "python_version >= '3.7'",
824
  "version": "==0.4.5"
825
  },
826
+ "setuptools": {
827
+ "hashes": [
828
+ "sha256:753bb6ebf1f465a1912e19ed1d41f403a79173a9acf66a42e7e6aec45c3c16ec",
829
+ "sha256:a7fcb66f68b4d9e8e66b42f9876150a3371558f98fa32222ffaa5bced76406f8"
830
+ ],
831
+ "markers": "python_version >= '3.12'",
832
+ "version": "==75.2.0"
833
+ },
834
  "six": {
835
  "hashes": [
836
  "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926",
models/{ESD-U/esd-vangogh_from_vangogh-noxattn_1-epochs_200.pt → ESD-X/esd-picasso_from_picasso-xattn_1-epochs_200.pt} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:dcdd21da7574a33e4fa2690e59c7b8695862eec92a3186b32f181af87b0b75c1
3
- size 3261580826
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f52f71a02de7c24b6191ec4385a6a5b08a7b2177458a7998dfffed28a6b49f50
3
+ size 175883766
upload.py CHANGED
@@ -1,55 +1,49 @@
1
- from huggingface_hub import HfApi, HfFolder, hf_hub_upload
2
  import os
3
- import subprocess
4
 
 
 
 
 
5
  hf_access_token = os.getenv("HUGGINGFACE_API_KEY")
6
- HfFolder.save_token(hf_access_token)
7
 
8
- MODEL_PATH = '/raid/aag/scasper/models/'
 
 
9
 
10
- def run_cleanup():
11
- try:
12
- subprocess.run(["python", "clean_folder.py"], check=True)
13
- print("Cleanup completed successfully.")
14
- except subprocess.CalledProcessError as e:
15
- print(f"Error running cleanup script: {e}")
16
- except FileNotFoundError:
17
- print("clean_folder.py not found in the current directory.")
18
 
19
  def is_repo_empty(repo_id):
20
- api = HfApi()
21
  try:
22
  files = api.list_repo_files(repo_id)
23
  return len(files) <= 2
24
  except Exception as e:
25
- print(f"An error occurred: {e}")
26
  return True
27
 
28
- def upload_pt_file(subdir, model_name, ckpt):
29
- file_path = f"{MODEL_PATH}{subdir}/{model_name}{ckpt}.pt"
30
- repo_id = f"LLM-GAT/{model_name}{ckpt}"
 
 
 
31
  if is_repo_empty(repo_id):
32
- hf_hub_upload(repo_id=repo_id, path_or_fileobj=file_path, token=hf_access_token)
33
- print(f"Uploaded {file_path} to {repo_id}")
 
 
 
 
34
  else:
35
- print(f"Repository {repo_id} is not empty. Skipping upload.")
36
-
37
- subdirs = ['gd']
38
- model_names = ['llama3_gd_lora-256-128_beta-14_bs-32_lr-1e-04_checkpoint-']
39
- ckpts = list(range(1, 9))
40
 
41
  def main():
42
- missing_models = []
43
- for subdir, model in zip(subdirs, model_names):
44
- for ckpt in ckpts:
45
- file_path = f"{MODEL_PATH}{subdir}/{model}{ckpt}.pt"
46
- if os.path.isfile(file_path):
47
- print(f"Uploading {file_path}...")
48
- upload_pt_file(subdir, model, ckpt)
49
- else:
50
- missing_models.append(file_path)
51
- run_cleanup()
52
- print('MISSING MODELS:', missing_models)
53
 
54
  if __name__ == "__main__":
55
- main()
 
1
+ from huggingface_hub import HfApi
2
  import os
3
+ from dotenv import load_dotenv
4
 
5
+ # Load environment variables from .env file
6
+ load_dotenv()
7
+
8
+ # Access Hugging Face API token
9
  hf_access_token = os.getenv("HUGGINGFACE_API_KEY")
10
+ print(hf_access_token) # Print to confirm loading, remove in production
11
 
12
+ # Base path to your models directory
13
+ MODEL_PATH = "/Users/klu/ErasingDiffusionModels/models/"
14
+ hf_username = "kevinlu4588" # replace with your Hugging Face username or org name
15
 
16
+ api = HfApi()
 
 
 
 
 
 
 
17
 
18
  def is_repo_empty(repo_id):
 
19
  try:
20
  files = api.list_repo_files(repo_id)
21
  return len(files) <= 2
22
  except Exception as e:
23
+ print(f"Error checking repository {repo_id}: {e}")
24
  return True
25
 
26
+ def upload_model_folder(subfolder_path):
27
+ model_name = os.path.basename(subfolder_path)
28
+ repo_id = f"{hf_username}/{model_name}"
29
+
30
+ # Create the repo if it doesn't exist, or skip if it has files
31
+ api.create_repo(repo_id, exist_ok=True, token=hf_access_token)
32
  if is_repo_empty(repo_id):
33
+ print(f"Uploading {subfolder_path} to {repo_id}...")
34
+ api.upload_folder(folder_path=subfolder_path,
35
+ repo_id=repo_id,
36
+ repo_type="model",
37
+ token=hf_access_token)
38
+ print(f"Successfully uploaded {subfolder_path} to {repo_id}.")
39
  else:
40
+ print(f"Repository {repo_id} already contains files. Skipping upload.")
 
 
 
 
41
 
42
  def main():
43
+ for subfolder in os.listdir(MODEL_PATH):
44
+ subfolder_path = os.path.join(MODEL_PATH, subfolder)
45
+ if os.path.isdir(subfolder_path):
46
+ upload_model_folder(subfolder_path)
 
 
 
 
 
 
 
47
 
48
  if __name__ == "__main__":
49
+ main()