func -> call
This commit is contained in:
@@ -1,18 +1,32 @@
|
||||
from fastapi import APIRouter, Response, UploadFile, responses
|
||||
from io import BytesIO
|
||||
|
||||
from fastapi import APIRouter, UploadFile, responses, Query
|
||||
from fastapi.responses import JSONResponse
|
||||
from rvc.modules.uvr5.modules import UVR
|
||||
from base64 import b64encode
|
||||
from scipy.io import wavfile
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.post("/inference")
|
||||
def uvr(inputpath, outputpath, modelname, format):
|
||||
uvr_module = UVR()
|
||||
uvr_module.uvr_wrapper(
|
||||
inputpath, outputpath, model_name=modelname, export_format=format
|
||||
)
|
||||
return responses.StreamingResponse(
|
||||
audio,
|
||||
media_type="audio/wav",
|
||||
headers={"Content-Disposition": "attachment; filename=inference.wav"},
|
||||
)
|
||||
def uvr(
|
||||
inputpath,
|
||||
outputpath,
|
||||
modelname,
|
||||
res_type: str = Query("blob", enum=["blob", "json"]),
|
||||
):
|
||||
arries = [i for i in UVR()(inputpath, outputpath, model_name=modelname)]
|
||||
wavfile.write(wv := BytesIO(), tgt_sr, audio_opt)
|
||||
if res_type == "blob":
|
||||
return responses.StreamingResponse(
|
||||
wv,
|
||||
media_type="audio/wav",
|
||||
headers={"Content-Disposition": "attachment; filename=inference.wav"},
|
||||
)
|
||||
else:
|
||||
return JSONResponse(
|
||||
{
|
||||
"audio": b64encode(wv.read()).decode("utf-8"),
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user