kemuririn
commited on
Commit
Β·
09c6470
1
Parent(s):
58df3ab
add api
Browse files
webui.py
CHANGED
|
@@ -15,6 +15,10 @@ import gradio as gr
|
|
| 15 |
from indextts.infer import IndexTTS
|
| 16 |
from tools.i18n.i18n import I18nAuto
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
i18n = I18nAuto(language="zh_CN")
|
| 19 |
MODE = 'local'
|
| 20 |
snapshot_download("IndexTeam/IndexTTS-1.5",local_dir="checkpoints",)
|
|
@@ -23,6 +27,8 @@ tts = IndexTTS(model_dir="checkpoints", cfg_path="checkpoints/config.yaml")
|
|
| 23 |
os.makedirs("outputs/tasks",exist_ok=True)
|
| 24 |
os.makedirs("prompts",exist_ok=True)
|
| 25 |
|
|
|
|
|
|
|
| 26 |
@spaces.GPU
|
| 27 |
def infer(voice, text,output_path=None):
|
| 28 |
if not tts:
|
|
@@ -32,6 +38,15 @@ def infer(voice, text,output_path=None):
|
|
| 32 |
tts.infer(voice, text, output_path)
|
| 33 |
return output_path
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
def gen_single(prompt, text):
|
| 36 |
output_path = infer(prompt, text)
|
| 37 |
return gr.update(value=output_path,visible=True)
|
|
@@ -70,11 +85,11 @@ with gr.Blocks() as demo:
|
|
| 70 |
inputs=[prompt_audio, input_text_single],
|
| 71 |
outputs=[output_audio])
|
| 72 |
|
|
|
|
| 73 |
|
| 74 |
def main():
|
| 75 |
tts.load_normalizer()
|
| 76 |
-
|
| 77 |
-
demo.launch(server_name="0.0.0.0")
|
| 78 |
|
| 79 |
if __name__ == "__main__":
|
| 80 |
main()
|
|
|
|
| 15 |
from indextts.infer import IndexTTS
|
| 16 |
from tools.i18n.i18n import I18nAuto
|
| 17 |
|
| 18 |
+
from fastapi import FastAPI, UploadFile, Form
|
| 19 |
+
from fastapi.responses import FileResponse, JSONResponse
|
| 20 |
+
import uvicorn
|
| 21 |
+
|
| 22 |
i18n = I18nAuto(language="zh_CN")
|
| 23 |
MODE = 'local'
|
| 24 |
snapshot_download("IndexTeam/IndexTTS-1.5",local_dir="checkpoints",)
|
|
|
|
| 27 |
os.makedirs("outputs/tasks",exist_ok=True)
|
| 28 |
os.makedirs("prompts",exist_ok=True)
|
| 29 |
|
| 30 |
+
app = FastAPI()
|
| 31 |
+
|
| 32 |
@spaces.GPU
|
| 33 |
def infer(voice, text,output_path=None):
|
| 34 |
if not tts:
|
|
|
|
| 38 |
tts.infer(voice, text, output_path)
|
| 39 |
return output_path
|
| 40 |
|
| 41 |
+
def tts_api(voice: str = Form(...), text: str = Form(...)):
|
| 42 |
+
try:
|
| 43 |
+
output_path = infer(voice, text)
|
| 44 |
+
return FileResponse(output_path, media_type="audio/wav", filename=output_path.split("/")[-1])
|
| 45 |
+
except Exception as e:
|
| 46 |
+
return JSONResponse(status_code=500, content={"error": str(e)})
|
| 47 |
+
|
| 48 |
+
app.post("/api/tts")(tts_api)
|
| 49 |
+
|
| 50 |
def gen_single(prompt, text):
|
| 51 |
output_path = infer(prompt, text)
|
| 52 |
return gr.update(value=output_path,visible=True)
|
|
|
|
| 85 |
inputs=[prompt_audio, input_text_single],
|
| 86 |
outputs=[output_audio])
|
| 87 |
|
| 88 |
+
gr.mount_gradio_app(app, demo, path="/")
|
| 89 |
|
| 90 |
def main():
|
| 91 |
tts.load_normalizer()
|
| 92 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
|
| 93 |
|
| 94 |
if __name__ == "__main__":
|
| 95 |
main()
|