JacobLinCool commited on
Commit
1d37aeb
1 Parent(s): b4b3999

feat: restore from hf

Browse files
Files changed (2) hide show
  1. app/export.py +6 -1
  2. app/setup.py +27 -0
app/export.py CHANGED
@@ -51,7 +51,12 @@ def download_expdir(exp_dir: str) -> str:
51
 
52
 
53
  def upload_to_huggingface(exp_dir: str, repo_id: str, token: str) -> str:
54
- commit = upload_folder(repo_id=repo_id, folder_path=exp_dir, token=token)
 
 
 
 
 
55
  return commit.commit_url
56
 
57
 
 
51
 
52
 
53
  def upload_to_huggingface(exp_dir: str, repo_id: str, token: str) -> str:
54
+ commit = upload_folder(
55
+ repo_id=repo_id,
56
+ folder_path=exp_dir,
57
+ ignore_patterns=["_data", "*.zip", "tmp.wav"],
58
+ token=token if token.startswith("hf_") else None,
59
+ )
60
  return commit.commit_url
61
 
62
 
app/setup.py CHANGED
@@ -5,6 +5,7 @@ import zipfile
5
  import tempfile
6
  from infer.modules.train.preprocess import PreProcess
7
  from typing import Tuple
 
8
 
9
 
10
  def extract_audio_files(zip_file: str, target_dir: str) -> list[str]:
@@ -45,6 +46,14 @@ def restore_expdir(zip: str) -> str:
45
  return exp_dir
46
 
47
 
 
 
 
 
 
 
 
 
48
  def set_dir(dir_val: str) -> str:
49
  if not dir_val.startswith("/tmp/"):
50
  dir_val = os.path.join("/tmp", dir_val)
@@ -84,6 +93,18 @@ class SetupTab:
84
  )
85
  self.restore_btn = gr.Button(value="Restore Experiment", variant="primary")
86
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  with gr.Row():
88
  self.dir_val = gr.Textbox(
89
  label="Manually set the experiment directory (don't touch it unless you know what you are doing)",
@@ -104,6 +125,12 @@ class SetupTab:
104
  outputs=[exp_dir],
105
  )
106
 
 
 
 
 
 
 
107
  self.set_dir_btn.click(
108
  fn=set_dir,
109
  inputs=[self.dir_val],
 
5
  import tempfile
6
  from infer.modules.train.preprocess import PreProcess
7
  from typing import Tuple
8
+ from huggingface_hub import snapshot_download
9
 
10
 
11
  def extract_audio_files(zip_file: str, target_dir: str) -> list[str]:
 
46
  return exp_dir
47
 
48
 
49
+ def restore_from_huggingface(repo: str, token: str) -> str:
50
+ exp_dir = os.path.join(tempfile.mkdtemp(), repo.lower())
51
+ snapshot_download(
52
+ repo, local_dir=exp_dir, token=token if token.startswith("hf_") else None
53
+ )
54
+ return exp_dir
55
+
56
+
57
  def set_dir(dir_val: str) -> str:
58
  if not dir_val.startswith("/tmp/"):
59
  dir_val = os.path.join("/tmp", dir_val)
 
93
  )
94
  self.restore_btn = gr.Button(value="Restore Experiment", variant="primary")
95
 
96
+ gr.Markdown("You can also restore from a Hugging Face repo.")
97
+ with gr.Row():
98
+ self.hf_repo = gr.Textbox(
99
+ label="Restore from Hugging Face repo",
100
+ placeholder="username/repo",
101
+ )
102
+ self.hf_token = gr.Textbox(
103
+ label="Hugging Face token (optional)",
104
+ placeholder="hf_...",
105
+ )
106
+ self.restore_hf_btn = gr.Button(value="Restore from Hugging Face")
107
+
108
  with gr.Row():
109
  self.dir_val = gr.Textbox(
110
  label="Manually set the experiment directory (don't touch it unless you know what you are doing)",
 
125
  outputs=[exp_dir],
126
  )
127
 
128
+ self.restore_hf_btn.click(
129
+ fn=restore_from_huggingface,
130
+ inputs=[self.hf_repo, self.hf_token],
131
+ outputs=[exp_dir],
132
+ )
133
+
134
  self.set_dir_btn.click(
135
  fn=set_dir,
136
  inputs=[self.dir_val],