Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
·
62e0727
1
Parent(s):
0c03e6c
Add setup script
Browse files
setup.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
import sys
|
| 4 |
+
import shutil
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
# setup.py will clone and install VibeVoice, copy voice files if they exist
|
| 8 |
+
|
| 9 |
+
def setup_vibevoice():
|
| 10 |
+
repo_dir = "VibeVoice"
|
| 11 |
+
original_dir = os.getcwd()
|
| 12 |
+
|
| 13 |
+
# clone repo if needed
|
| 14 |
+
if not os.path.exists(repo_dir):
|
| 15 |
+
print("Cloning the VibeVoice repository...")
|
| 16 |
+
try:
|
| 17 |
+
subprocess.run(
|
| 18 |
+
["git", "clone", "https://github.com/microsoft/VibeVoice.git"],
|
| 19 |
+
check=True,
|
| 20 |
+
capture_output=True,
|
| 21 |
+
text=True
|
| 22 |
+
)
|
| 23 |
+
print("Repository cloned successfully.")
|
| 24 |
+
except subprocess.CalledProcessError as e:
|
| 25 |
+
print(f"Error cloning repository: {e.stderr}")
|
| 26 |
+
sys.exit(1)
|
| 27 |
+
else:
|
| 28 |
+
print("Repository already exists. Skipping clone.")
|
| 29 |
+
|
| 30 |
+
# install the package
|
| 31 |
+
os.chdir(repo_dir)
|
| 32 |
+
print(f"Changed directory to: {os.getcwd()}")
|
| 33 |
+
|
| 34 |
+
print("Installing the VibeVoice package...")
|
| 35 |
+
try:
|
| 36 |
+
subprocess.run(
|
| 37 |
+
[sys.executable, "-m", "pip", "install", "-e", "."],
|
| 38 |
+
check=True,
|
| 39 |
+
capture_output=True,
|
| 40 |
+
text=True
|
| 41 |
+
)
|
| 42 |
+
print("Package installed successfully.")
|
| 43 |
+
except subprocess.CalledProcessError as e:
|
| 44 |
+
print(f"Error installing package: {e.stderr}")
|
| 45 |
+
sys.exit(1)
|
| 46 |
+
|
| 47 |
+
# add to python path
|
| 48 |
+
sys.path.insert(0, os.getcwd())
|
| 49 |
+
|
| 50 |
+
# go back to original directory
|
| 51 |
+
os.chdir(original_dir)
|
| 52 |
+
print(f"Changed back to original directory: {os.getcwd()}")
|
| 53 |
+
|
| 54 |
+
# copy voice files if they exist
|
| 55 |
+
if os.path.exists("public/voices"):
|
| 56 |
+
target_voices_dir = os.path.join(repo_dir, "demo", "voices")
|
| 57 |
+
|
| 58 |
+
# clear existing voices and use only ours
|
| 59 |
+
if os.path.exists(target_voices_dir):
|
| 60 |
+
shutil.rmtree(target_voices_dir)
|
| 61 |
+
os.makedirs(target_voices_dir)
|
| 62 |
+
|
| 63 |
+
for file in os.listdir("public/voices"):
|
| 64 |
+
if file.endswith(('.mp3', '.wav', '.flac', '.ogg', '.m4a', '.aac')):
|
| 65 |
+
src = os.path.join("public/voices", file)
|
| 66 |
+
dst = os.path.join(target_voices_dir, file)
|
| 67 |
+
shutil.copy2(src, dst)
|
| 68 |
+
print(f"Copied voice file: {file}")
|
| 69 |
+
|
| 70 |
+
return repo_dir
|
| 71 |
+
|
| 72 |
+
def setup_voice_presets():
|
| 73 |
+
# get voice files from vibevoice demo directory
|
| 74 |
+
voices_dir = Path("VibeVoice/demo/voices")
|
| 75 |
+
|
| 76 |
+
voice_presets = {}
|
| 77 |
+
audio_extensions = ('.wav', '.mp3', '.flac', '.ogg', '.m4a', '.aac')
|
| 78 |
+
|
| 79 |
+
if voices_dir.exists():
|
| 80 |
+
for audio_file in voices_dir.glob("*"):
|
| 81 |
+
if audio_file.suffix.lower() in audio_extensions:
|
| 82 |
+
name = audio_file.stem
|
| 83 |
+
voice_presets[name] = str(audio_file)
|
| 84 |
+
|
| 85 |
+
# if no voices found, create directory
|
| 86 |
+
if not voice_presets and not voices_dir.exists():
|
| 87 |
+
voices_dir.mkdir(parents=True, exist_ok=True)
|
| 88 |
+
|
| 89 |
+
return dict(sorted(voice_presets.items()))
|