Spaces:
Running
Running
Update scripts/setup_third_party.py
Browse files- scripts/setup_third_party.py +101 -74
scripts/setup_third_party.py
CHANGED
|
@@ -1,75 +1,102 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import shutil
|
| 3 |
-
import subprocess
|
| 4 |
-
import argparse
|
| 5 |
-
import sys
|
| 6 |
-
|
| 7 |
-
def
|
| 8 |
-
"""
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
print(f"
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
)
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
)
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
main(args)
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import shutil
|
| 3 |
+
import subprocess
|
| 4 |
+
import argparse
|
| 5 |
+
import sys
|
| 6 |
+
|
| 7 |
+
def install_editable_package():
|
| 8 |
+
"""Install the f5-tts package in editable mode without dependencies."""
|
| 9 |
+
try:
|
| 10 |
+
subprocess.run(
|
| 11 |
+
[sys.executable, "-m", "pip", "install", "-e", ".", "--no-deps"],
|
| 12 |
+
check=True,
|
| 13 |
+
capture_output=True,
|
| 14 |
+
text=True
|
| 15 |
+
)
|
| 16 |
+
print("Successfully installed f5-tts package in editable mode")
|
| 17 |
+
except subprocess.CalledProcessError as e:
|
| 18 |
+
print(f"Failed to install f5-tts package: {e.stderr}")
|
| 19 |
+
sys.exit(1)
|
| 20 |
+
|
| 21 |
+
def clone_repository(repo_url, target_dir, branch="main"):
|
| 22 |
+
"""Clone a git repository to the specified directory with specific branch."""
|
| 23 |
+
if os.path.exists(target_dir):
|
| 24 |
+
print(f"Directory {target_dir} already exists. Skipping clone.")
|
| 25 |
+
return
|
| 26 |
+
|
| 27 |
+
os.makedirs(os.path.dirname(target_dir), exist_ok=True)
|
| 28 |
+
|
| 29 |
+
try:
|
| 30 |
+
subprocess.run(
|
| 31 |
+
["git", "clone", "-b", branch, repo_url, target_dir],
|
| 32 |
+
check=True,
|
| 33 |
+
capture_output=True,
|
| 34 |
+
text=True
|
| 35 |
+
)
|
| 36 |
+
print(f"Successfully cloned {repo_url} (branch: {branch}) to {target_dir}")
|
| 37 |
+
except subprocess.CalledProcessError as e:
|
| 38 |
+
print(f"Failed to clone repository: {e.stderr}")
|
| 39 |
+
sys.exit(1)
|
| 40 |
+
|
| 41 |
+
def handle_remove_readonly(func, path, _):
|
| 42 |
+
os.chmod(path, 0o666)
|
| 43 |
+
func(path)
|
| 44 |
+
|
| 45 |
+
def setup_python_path():
|
| 46 |
+
"""Add the src directory to sys.path to allow module imports."""
|
| 47 |
+
src_dir = os.path.abspath("src")
|
| 48 |
+
if src_dir not in sys.path:
|
| 49 |
+
sys.path.insert(0, src_dir)
|
| 50 |
+
print(f"Added {src_dir} to sys.path")
|
| 51 |
+
else:
|
| 52 |
+
print(f"{src_dir} already in sys.path")
|
| 53 |
+
|
| 54 |
+
def main(args):
|
| 55 |
+
# Define target directories
|
| 56 |
+
temp_f5_tts_target_dir = os.path.join("src", "danhtran2mind_f5_tts")
|
| 57 |
+
bigvgan_target_dir = os.path.join("src", "third_party", "BigVGAN")
|
| 58 |
+
f5_tts_target_dir = os.path.join("src", "f5_tts")
|
| 59 |
+
|
| 60 |
+
# Clone F5-TTS repository
|
| 61 |
+
clone_repository(args.f5_tts_url, temp_f5_tts_target_dir, args.f5_tts_branch)
|
| 62 |
+
|
| 63 |
+
# Clone BigVGAN repository
|
| 64 |
+
clone_repository(args.bigvgan_url, bigvgan_target_dir, args.bigvgan_branch)
|
| 65 |
+
|
| 66 |
+
# Move the directory
|
| 67 |
+
shutil.move(os.path.join(temp_f5_tts_target_dir, "src", "f5_tts"), f5_tts_target_dir)
|
| 68 |
+
shutil.copytree(os.path.join(temp_f5_tts_target_dir, "data"), "./data", dirs_exist_ok=True)
|
| 69 |
+
# Remove the nested f5_tts directory
|
| 70 |
+
if os.path.exists(os.path.join(f5_tts_target_dir, "f5_tts")):
|
| 71 |
+
shutil.rmtree(os.path.join(f5_tts_target_dir, "f5_tts"), onerror=handle_remove_readonly)
|
| 72 |
+
# Remove the parent directory
|
| 73 |
+
shutil.rmtree(temp_f5_tts_target_dir, onerror=handle_remove_readonly)
|
| 74 |
+
|
| 75 |
+
# Set up Python path to include src directory
|
| 76 |
+
install_editable_package()
|
| 77 |
+
|
| 78 |
+
if __name__ == "__main__":
|
| 79 |
+
parser = argparse.ArgumentParser(description="Clone F5-TTS and BigVGAN repositories and set up Python path")
|
| 80 |
+
parser.add_argument(
|
| 81 |
+
"--f5-tts-url",
|
| 82 |
+
default="https://github.com/danhtran2mind/F5-TTS",
|
| 83 |
+
help="URL for F5-TTS repository"
|
| 84 |
+
)
|
| 85 |
+
parser.add_argument(
|
| 86 |
+
"--bigvgan-url",
|
| 87 |
+
default="https://github.com/NVIDIA/BigVGAN",
|
| 88 |
+
help="URL for BigVGAN repository"
|
| 89 |
+
)
|
| 90 |
+
parser.add_argument(
|
| 91 |
+
"--f5-tts-branch",
|
| 92 |
+
default="main",
|
| 93 |
+
help="Branch for F5-TTS repository"
|
| 94 |
+
)
|
| 95 |
+
parser.add_argument(
|
| 96 |
+
"--bigvgan-branch",
|
| 97 |
+
default="main",
|
| 98 |
+
help="Branch or commit for BigVGAN repository"
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
args = parser.parse_args()
|
| 102 |
main(args)
|