forked from blaisewf/rvc-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.py
93 lines (68 loc) · 2.33 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from fastapi import FastAPI, Request
import subprocess
import time
app = FastAPI()
# Helper function to execute commands
def execute_command(command):
try:
result = subprocess.run(command, capture_output=True, text=True)
return {"output": result.stdout, "error": result.stderr}
except Exception as e:
return {"error": str(e)}
# Infer
@app.post("/infer")
async def infer(request: Request):
command = ["python", "rvc.py", "infer"] + await request.json()
return execute_command(command)
# Batch Infer
@app.post("/batch_infer")
async def batch_infer(request: Request):
command = ["python", "rvc.py", "batch_infer"] + await request.json()
return execute_command(command)
# TTS
@app.post("/tts")
async def tts(request: Request):
command = ["python", "rvc.py", "tts"] + await request.json()
return execute_command(command)
# Preprocess
@app.post("/preprocess")
async def preprocess(request: Request):
command = ["python", "rvc.py", "preprocess"] + await request.json()
return execute_command(command)
# Extract
@app.post("/extract")
async def extract(request: Request):
command = ["python", "rvc.py", "extract"] + await request.json()
return execute_command(command)
# Train
@app.post("/train")
async def train(request: Request):
command = ["python", "rvc.py", "train"] + await request.json()
return execute_command(command)
# Index
@app.post("/index")
async def index(request: Request):
command = ["python", "rvc.py", "index"] + await request.json()
return execute_command(command)
# Model Information
@app.post("/model_information")
async def model_information(request: Request):
command = ["python", "rvc.py", "model_information"] + await request.json()
return execute_command(command)
# Model Fusion
@app.post("/model_fusion")
async def model_fusion(request: Request):
command = ["python", "rvc.py", "model_fusion"] + await request.json()
return execute_command(command)
# Download
@app.post("/download")
async def download(request: Request):
command = ["python", "rvc.py", "download"] + await request.json()
return execute_command(command)
# Ping endpoint to check latency
@app.get("/ping")
async def ping():
start_time = time.time()
end_time = time.time()
latency = end_time - start_time
return {"ping": "pong", "latency": latency}