Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from rsxdalv/adapting-for-tts
Browse files Browse the repository at this point in the history
Adapting for TTS
  • Loading branch information
rsxdalv authored Apr 30, 2023
2 parents bcd5786 + 0f4a5e0 commit a7299b0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 85 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
installer_files/
105 changes: 20 additions & 85 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,99 +51,39 @@ def install_dependencies():
sys.exit()

# Clone webui to our computer
run_cmd("git clone https://github.com/oobabooga/text-generation-webui.git")
if sys.platform.startswith("win"):
# Fix a bitsandbytes compatibility issue with Windows
run_cmd("python -m pip install https://github.com/jllllll/bitsandbytes-windows-webui/raw/main/bitsandbytes-0.38.1-py3-none-any.whl")

run_cmd("git clone https://github.com/rsxdalv/tts-generation-webui.git")
run_cmd("git clone https://github.com/rsxdalv/bark.git tts-generation-webui/models/bark")
run_cmd("git clone https://github.com/rsxdalv/tortoise-tts.git tts-generation-webui/models/turtoise-tts")
run_cmd("pip install python-dotenv")
run_cmd("pip install gradio")
run_cmd("pip install soundfile") # torchaudio platform windows
# run_cmd("pip install sox") # torchaudio platform linux

# Install the webui dependencies
update_dependencies()


def update_dependencies():
os.chdir("text-generation-webui")
os.chdir("tts-generation-webui/models/bark")
run_cmd("git pull")

# Installs/Updates dependencies from all requirements.txt
run_cmd("python -m pip install -r requirements.txt --upgrade")
extensions = next(os.walk("extensions"))[1]
for extension in extensions:
extension_req_path = os.path.join("extensions", extension, "requirements.txt")
if os.path.exists(extension_req_path):
run_cmd("python -m pip install -r " + extension_req_path + " --upgrade")

# The following dependencies are for CUDA, not CPU
# Check if the package cpuonly exists to determine if torch uses CUDA or not
cpuonly_exist = not run_cmd("conda list cpuonly | grep cpuonly", capture_output=True).returncode
if cpuonly_exist:
return

# Finds the path to your dependencies
for sitedir in site.getsitepackages():
if "site-packages" in sitedir:
site_packages_path = sitedir
break

# This path is critical to installing the following dependencies
if site_packages_path is None:
print("Could not find the path to your Python packages. Exiting...")
sys.exit()
run_cmd("python -m pip install .")
os.chdir(script_dir)

# Fix a bitsandbytes compatibility issue with Linux
if sys.platform.startswith("linux"):
shutil.copy(os.path.join(site_packages_path, "bitsandbytes", "libbitsandbytes_cuda117.so"), os.path.join(site_packages_path, "bitsandbytes", "libbitsandbytes_cpu.so"))

if not os.path.exists("repositories/"):
os.mkdir("repositories")

# Install GPTQ-for-LLaMa which enables 4bit CUDA quantization
os.chdir("repositories")
if not os.path.exists("GPTQ-for-LLaMa/"):
run_cmd("git clone https://github.com/oobabooga/GPTQ-for-LLaMa.git -b cuda")

# Install GPTQ-for-LLaMa dependencies
os.chdir("GPTQ-for-LLaMa")
os.chdir("tts-generation-webui/models/turtoise-tts")
run_cmd("git pull")
run_cmd("python -m pip install -r requirements.txt")

# On some Linux distributions, g++ may not exist or be the wrong version to compile GPTQ-for-LLaMa
install_flag = True
if sys.platform.startswith("linux"):
gxx_output = run_cmd("g++ --version", capture_output=True)
if gxx_output.returncode != 0 or b"g++ (GCC) 12" in gxx_output.stdout:
# Install the correct version of g++
run_cmd("conda install -y -k gxx_linux-64=11.2.0")

# Activate the conda environment to compile GPTQ-for-LLaMa
conda_env_path = os.path.join(script_dir, "installer_files", "env")
conda_sh_path = os.path.join(script_dir, "installer_files", "conda", "etc", "profile.d", "conda.sh")
run_cmd(". " + conda_sh_path + " && conda activate " + conda_env_path + " && python setup_cuda.py install")
install_flag = False

if install_flag:
run_cmd("python setup_cuda.py install")
install_flag = False

# If the path does not exist, then the install failed
quant_cuda_path_regex = os.path.join(site_packages_path, "quant_cuda*/")
if not glob.glob(quant_cuda_path_regex):
print("CUDA kernel compilation failed.")
# Attempt installation via alternative, Windows-specific method
if sys.platform.startswith("win"):
print("Attempting installation with wheel.")
result = run_cmd("python -m pip install https://github.com/jllllll/GPTQ-for-LLaMa-Wheels/raw/main/quant_cuda-0.0.0-cp310-cp310-win_amd64.whl")
if result.returncode == 1:
print("Wheel installation failed.")


def download_model():
os.chdir("text-generation-webui")
run_cmd("python download-model.py")
# Installs/Updates dependencies from all requirements.txt
run_cmd("pip install transformers==4.19.0")
run_cmd("pip install -r requirements.txt")
run_cmd("python setup.py install")
run_cmd("conda install -y --channel=numba llvmlite")


def run_model():
os.chdir("text-generation-webui")
run_cmd("python server.py --chat --model-menu") # put your flags here!
os.chdir("tts-generation-webui")
run_cmd("python server.py") # put your flags here!


if __name__ == "__main__":
Expand All @@ -158,14 +98,9 @@ def run_model():
update_dependencies()
else:
# If webui has already been installed, skip and run
if not os.path.exists("text-generation-webui/"):
if not os.path.exists("tts-generation-webui/"):
install_dependencies()
os.chdir(script_dir)

# Check if a model has been downloaded yet
if len(glob.glob("text-generation-webui/models/*/")) == 0:
download_model()
os.chdir(script_dir)

# Run the model with webui
run_model()

0 comments on commit a7299b0

Please sign in to comment.