hugo flores garcia commited on
Commit
3c83fc3
·
1 Parent(s): 84b19f5

simplify the upload instructions.

Browse files
Files changed (2) hide show
  1. README.md +3 -21
  2. scripts/exp/export.py +40 -7
README.md CHANGED
@@ -172,35 +172,17 @@ Once your model has been fine-tuned, you can export it to a HuggingFace model.
172
 
173
  In order to use your model in `app.py`, you will need to export it to HuggingFace.
174
 
175
- **NOTE**: In order to export, you will need a [huggingface account](https://huggingface.co/).
176
-
177
- <!-- You need to fork the [vampnet models repo](https://huggingface.co/hugggof/vampnet) which stores the default vampnet models. -->
178
-
179
- Now, create a repo on huggingface. You can do this by going to the huggingface website and clicking on the "Create a new model" button.
180
- Copy your repo name. It should look something like `<USERNAME>/vampnet`.
181
-
182
- Now, navigate to `models/vampnet` and add your new repo as a remote:
183
-
184
- ```bash
185
- cd ./models/vampnet && git init && git remote add origin https://huggingface.co/<YOUR_REPO_NAME> && git pull origin main
186
- ```
187
- go back
188
-
189
- ```bash
190
- cd ../../
191
- ```
192
-
193
- Now, replace the contents of the file named `./DEFAULT_HF_MODEL_REPO` in the root folder with the name of your repo (usually `<USERNAME>/vampnet`).
194
 
195
  Now, log in to huggingface using the command line:
196
  ```bash
197
  huggingface-cli login
198
  ```
199
 
200
- Now, run the following command to export your model:
201
 
202
  ```bash
203
- python scripts/exp/export.py --name <your_finetuned_model_name> --model latest
204
  ```
205
 
206
  Once that's done, your model should appear on the list of available models in the gradio interface.
 
172
 
173
  In order to use your model in `app.py`, you will need to export it to HuggingFace.
174
 
175
+ **NOTE**: In order to export, you will need a [huggingface account](https://huggingface.co/).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
 
177
  Now, log in to huggingface using the command line:
178
  ```bash
179
  huggingface-cli login
180
  ```
181
 
182
+ Now, run the following command to export your model (replace `<your_finetuned_model_name>` with the name of your model, and `<HUGGINGFACE_USERNAME>` with your huggingface username):
183
 
184
  ```bash
185
+ python scripts/exp/export.py --name <your_finetuned_model_name> --model latest --repo <HUGGINGFACE_USERNAME>/vampnet
186
  ```
187
 
188
  Once that's done, your model should appear on the list of available models in the gradio interface.
scripts/exp/export.py CHANGED
@@ -3,6 +3,8 @@ from pathlib import Path
3
  import shutil
4
  import argparse
5
  from vampnet import DEFAULT_HF_MODEL_REPO
 
 
6
 
7
 
8
  parser = argparse.ArgumentParser(description="Export the fine-tuned model to the repo")
@@ -14,14 +16,31 @@ parser.add_argument(
14
  "--model", type=str, default="latest",
15
  help="model version to export. check runs/<name> for available versions"
16
  )
 
 
 
 
17
 
18
  args = parser.parse_args()
19
  name = args.name
20
  version = args.model
21
 
 
 
 
 
22
  run_dir = Path(f"runs/{name}")
23
  repo_dir = Path("models/vampnet")
24
 
 
 
 
 
 
 
 
 
 
25
  for part in ("coarse", "c2f"):
26
  outdir = repo_dir / "loras" / name
27
  outdir.mkdir(parents=True, exist_ok=True)
@@ -29,13 +48,27 @@ for part in ("coarse", "c2f"):
29
  path = run_dir / part / version / "vampnet" / "weights.pth"
30
  # path.rename(outpath)
31
  shutil.copy(path, outpath)
 
32
  print(f"moved {path} to {outpath}")
33
 
34
- from huggingface_hub import Repository
35
- repo = Repository(str(repo_dir),clone_from=f"https://huggingface.co/{DEFAULT_HF_MODEL_REPO}")
36
- print(f"pushing {repo_dir} to {name}")
37
- print(f"howdy! I am pushing to {DEFAULT_HF_MODEL_REPO} :)")
38
- repo.push_to_hub(
39
- commit_message=f"add {name}",
40
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  print("done!!! >::0")
 
3
  import shutil
4
  import argparse
5
  from vampnet import DEFAULT_HF_MODEL_REPO
6
+ from huggingface_hub import create_repo, repo_exists, HfApi
7
+
8
 
9
 
10
  parser = argparse.ArgumentParser(description="Export the fine-tuned model to the repo")
 
16
  "--model", type=str, default="latest",
17
  help="model version to export. check runs/<name> for available versions"
18
  )
19
+ parser.add_argument(
20
+ "--repo", type=str, default=DEFAULT_HF_MODEL_REPO,
21
+ help="name of the repo to export to"
22
+ )
23
 
24
  args = parser.parse_args()
25
  name = args.name
26
  version = args.model
27
 
28
+ ##
29
+ print(f"~~~~~~~~~~~ vampnet export! ~~~~~~~~~~~~")
30
+ print(f"exporting {name} version {version} to {args.repo}\n")
31
+
32
  run_dir = Path(f"runs/{name}")
33
  repo_dir = Path("models/vampnet")
34
 
35
+ # create our repo
36
+ new_repo = False
37
+ if not repo_exists(args.repo):
38
+ print(f"repo {args.repo} does not exist, creating it")
39
+ print(f"creating a repo at {args.repo}")
40
+ create_repo(args.repo)
41
+ new_repo = True
42
+
43
+ paths = []
44
  for part in ("coarse", "c2f"):
45
  outdir = repo_dir / "loras" / name
46
  outdir.mkdir(parents=True, exist_ok=True)
 
48
  path = run_dir / part / version / "vampnet" / "weights.pth"
49
  # path.rename(outpath)
50
  shutil.copy(path, outpath)
51
+ paths.append(outpath)
52
  print(f"moved {path} to {outpath}")
53
 
54
+ print(f"uploading files to {args.repo}")
55
+ # upload files to the repo
56
+
57
+ # if it's a new repo, let's add the default models too
58
+ defaults = [repo_dir / "c2f.pth", repo_dir / "coarse.pth", repo_dir / "codec.pth", repo_dir / "wavebeat.pth"]
59
+
60
+ api = HfApi()
61
+
62
+ for path in paths:
63
+ path_in_repo = str(path.relative_to(repo_dir))
64
+ print(f"uploading {path} to {args.repo}/{path_in_repo}")
65
+ api.upload_file(
66
+ path_or_fileobj=path,
67
+ path_in_repo=path_in_repo,
68
+ repo_id=args.repo,
69
+ token=True,
70
+ commit_message=f"uploading {path_in_repo}",
71
+ )
72
+
73
+
74
  print("done!!! >::0")