daswer123 / xtts-api-server

A simple FastAPI Server to run XTTSv2
MIT License
290 stars 67 forks source link

The colab is not working anymore #78

Open LostRuins opened 1 month ago

LostRuins commented 1 month ago

It seems like the colab is not working anymore, possibly due to some updated python packages?

VermiNew commented 1 month ago

Try this, it should work (Works for me):

load_samples = True

print("Installing Packages and Dependencies\nPlease wait 2-3 minutes")
!npm install localtunnel
!apt install libasound2-dev portaudio19-dev libportaudio2 libportaudiocpp0 ffmpeg -y

print("Installing main packages...")
!pip install torch==2.1.1+cu118 torchaudio==2.1.1+cu118 --index-url https://download.pytorch.org/whl/cu118
print("Installing XTTS-V2 API SERVER...")
!pip install xtts-api-server
print("Force reinstalling numpy packet... 'numpy==1.26.2'...")
!pip install --force-reinstall numpy==1.26.2

# Install cloudflare as alternative
!wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
!apt install ./cloudflared-linux-amd64.deb aria2 -y
!rm cloudflared-linux-amd64.deb

# Deepspeed
print("Installing deepspeed...")
!pip install deepspeed

# copy exaple sample
if load_samples:
    print("Creating folder... 'speakers'...")
    !mkdir speakers

print("Finally, done!")
VermiNew commented 2 weeks ago

Try using my code:

print("Installing Packages and Dependencies\nPlease wait...\n\n")

# =-=-=-=-=-=-=-=-=-=-=-=-=-=- DO NOT EDIT CODE HERE =-=-=-=-=-=-=-=-=-=-=-=-=-=-
# NPM Update
print("Updating npm...")
!npm install -g npm@10.8.1

# Localtunnel
print("Installing localtunnel...")
!npm install localtunnel

# Linux packages
print("Installing audio dependencies and other required packages...")
!apt install libasound2-dev portaudio19-dev libportaudio2 libportaudiocpp0 ffmpeg -y

# PyTorch
print("Installing main packages...")
!pip install torch==2.1.1+cu118 torchaudio==2.1.1+cu118 --index-url https://download.pytorch.org/whl/cu118

# TTS for API Server
print("Installing TTS...")
!pip install TTS

# XTTS API Server
print("Installing XTTS API Server...")
!pip install --upgrade xtts-api-server

# Numpy
print("Reinstalling numpy...")
!pip install --force-reinstall numpy==1.26.2

# Deepspeed library installation
print("Installing deepspeed...")
!pip install deepspeed

# Install cloudflare as alternative
print("Installing cloudflare...")
!wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
!apt install ./cloudflared-linux-amd64.deb aria2 -y
!rm cloudflared-linux-amd64.deb

# Create speakers folder for TTS voices
print('Creating folder named "speakers"...')
!mkdir speakers

# Done
print("-" * 21)
print("-->\t\tFinally, done!")
print("-" * 21)
print("Now you can start next cell.")
print("-" * 21)
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

# TTS Code
import subprocess
import re

use_deepspeed = True
Tunnel = "localtunnel"
Model_version = "v2.0.3"
Model_source = "local"

# =-=-=-=-=-=-=-=-=-=-=-=-=-=- DO NOT EDIT CODE HERE =-=-=-=-=-=-=-=-=-=-=-=-=-=-
group = 1
host = "127.0.0.1"

def pip_list_comma_separated():
    result = subprocess.run(['pip', 'list'], stdout=subprocess.PIPE)
    pip_list_output = result.stdout.decode('utf-8')
    lines = pip_list_output.splitlines()

    package_lines = lines[2:]
    packages = [line.split()[0] for line in package_lines]
    comma_separated_packages = ', '.join(packages)

    print(comma_separated_packages)

# Display installed libraries
print("-" * 21)
print("Displaying installed libraries...")
pip_list_comma_separated()
print("-" * 21)

# Starting a tunnel.
print(f"Starting tunnel using {Tunnel}...")
if Tunnel == "cloudflare":
    subprocess.Popen(['cloudflared', '--url', 'http://127.0.0.1:8020'], stdout=open('lt.log', 'w'), stderr=subprocess.STDOUT)
    group -= 1
else:
    subprocess.Popen(['npx', 'lt', '-p', '8020'], stdout=open('lt.log', 'w'), stderr=subprocess.STDOUT)
    print()

print("Checking...")
tunnel_url = ''

# Open the file for reading.
print("Reading tunnel log...")
with open('lt.log', 'r') as testwritefile:
    log_content = testwritefile.read()
    url_match = ""

    # Use regular expressions to find the URL.
    if Tunnel == "cloudflare":
        url_match = re.search(r'https:\/\/[a-z-]+\.trycloudflare\.com', log_content)
    else:
        url_match = re.search(r'your url is: (https?://\S+)', log_content)

    if url_match:
        tunnel_url = url_match.group(group)
        print(f"Your url for SillyTavern: {tunnel_url}")
    else:
        print("URL not found.")

if Model_source == "api":
    host = "0.0.0.0"

if Tunnel == "localtunnel":
    print("Fetching your public IP address...")
    !curl ipv4.icanhazip.com

print("\n" + "-" * 21)

# Deepspeed
deepspeed_flag = ""
if use_deepspeed:
    deepspeed_flag = "--deepspeed"

# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# Start API server.
print("Starting API server...")
!python -m xtts_api_server {deepspeed_flag} -hs {host} -t {tunnel_url} -ms {Model_source} -v {Model_version}
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
LostRuins commented 2 weeks ago

Cool thanks. Hoping this project stays maintained

VermiNew commented 2 weeks ago

No problem, I also hope they don't abandon this project because I use this TTS for my private AI and would be saddened by a change to another solution.