mirror of
https://github.com/FunAudioLLM/CosyVoice.git
synced 2026-02-04 09:29:25 +08:00
add fastapi usage
This commit is contained in:
@@ -135,6 +135,8 @@ docker build -t cosyvoice:v1.0 .
|
||||
docker run -d --runtime=nvidia -p 50000:50000 cosyvoice:v1.0 /bin/bash -c "cd /opt/CosyVoice/CosyVoice/runtime/python/grpc && python3 server.py --port 50000 --max_conc 4 --model_dir iic/CosyVoice-300M && sleep infinity"
|
||||
python3 grpc/client.py --port 50000 --mode <sft|zero_shot|cross_lingual|instruct>
|
||||
# for fastapi usage
|
||||
docker run -d --runtime=nvidia -p 50000:50000 cosyvoice:v1.0 /bin/bash -c "cd /opt/CosyVoice/CosyVoice/runtime/python/fastapi && MODEL_DIR=iic/CosyVoice-300M fastapi dev --port 50000 server.py && sleep infinity"
|
||||
python3 fastapi/client.py --port 50000 --mode <sft|zero_shot|cross_lingual|instruct>
|
||||
```
|
||||
|
||||
## Discussion & Communication
|
||||
|
||||
@@ -66,7 +66,7 @@ if __name__ == "__main__":
|
||||
default='希望你以后能够做的比我还好呦。')
|
||||
parser.add_argument('--prompt_wav',
|
||||
type=str,
|
||||
default='../../zero_shot_prompt.wav')
|
||||
default='../../../zero_shot_prompt.wav')
|
||||
parser.add_argument('--instruct_text',
|
||||
type=str,
|
||||
default='Theo \'Crimson\', is a fiery, passionate rebel leader. Fights with fervor for justice, but struggles with impulsiveness.')
|
||||
@@ -1,9 +1,9 @@
|
||||
# Set inference model
|
||||
# export MODEL_DIR=pretrained_models/CosyVoice-300M-Instruct
|
||||
# For development
|
||||
# fastapi dev --port 6006 fastapi_server.py
|
||||
# fastapi dev --port 6006 fastapi_server.py
|
||||
# For production deployment
|
||||
# fastapi run --port 6006 fastapi_server.py
|
||||
# fastapi run --port 6006 fastapi_server.py
|
||||
|
||||
import os
|
||||
import sys
|
||||
@@ -12,8 +12,8 @@ from fastapi import FastAPI, Response, File, UploadFile, Form
|
||||
from fastapi.responses import HTMLResponse
|
||||
from contextlib import asynccontextmanager
|
||||
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
sys.path.append('{}/../..'.format(ROOT_DIR))
|
||||
sys.path.append('{}/../../third_party/Matcha-TTS'.format(ROOT_DIR))
|
||||
sys.path.append('{}/../../..'.format(ROOT_DIR))
|
||||
sys.path.append('{}/../../../third_party/Matcha-TTS'.format(ROOT_DIR))
|
||||
from cosyvoice.cli.cosyvoice import CosyVoice
|
||||
from cosyvoice.utils.file_utils import load_wav
|
||||
import numpy as np
|
||||
@@ -30,7 +30,7 @@ async def lifespan(app: FastAPI):
|
||||
model_dir = os.getenv("MODEL_DIR", "pretrained_models/CosyVoice-300M-SFT")
|
||||
if model_dir:
|
||||
logging.info("MODEL_DIR is {}", model_dir)
|
||||
app.cosyvoice = CosyVoice('../../'+model_dir)
|
||||
app.cosyvoice = CosyVoice(model_dir)
|
||||
# sft usage
|
||||
logging.info("Avaliable speakers {}", app.cosyvoice.list_avaliable_spks())
|
||||
else:
|
||||
Reference in New Issue
Block a user