separate fileuploader
This commit is contained in:
parent
705f014a6c
commit
069737ff0a
@ -134,27 +134,27 @@ if __name__ == thisFilename or args.colab == True:
|
||||
MODEL_DIR = "MMVC_Trainer/logs"
|
||||
os.makedirs(MODEL_DIR, exist_ok=True)
|
||||
|
||||
@app_fastapi.post("/upload_file")
|
||||
async def post_upload_file(
|
||||
file: UploadFile = File(...),
|
||||
filename: str = Form(...)
|
||||
):
|
||||
return upload_file(UPLOAD_DIR, file, filename)
|
||||
# @app_fastapi.post("/upload_file")
|
||||
# async def post_upload_file(
|
||||
# file: UploadFile = File(...),
|
||||
# filename: str = Form(...)
|
||||
# ):
|
||||
# return upload_file(UPLOAD_DIR, file, filename)
|
||||
|
||||
@app_fastapi.post("/load_model")
|
||||
async def post_load_model(
|
||||
modelFilename: str = Form(...),
|
||||
modelFilenameChunkNum: int = Form(...),
|
||||
configFilename: str = Form(...)
|
||||
):
|
||||
# @app_fastapi.post("/load_model")
|
||||
# async def post_load_model(
|
||||
# modelFilename: str = Form(...),
|
||||
# modelFilenameChunkNum: int = Form(...),
|
||||
# configFilename: str = Form(...)
|
||||
# ):
|
||||
|
||||
modelFilePath = concat_file_chunks(
|
||||
UPLOAD_DIR, modelFilename, modelFilenameChunkNum, UPLOAD_DIR)
|
||||
print(f'File saved to: {modelFilePath}')
|
||||
configFilePath = os.path.join(UPLOAD_DIR, configFilename)
|
||||
# modelFilePath = concat_file_chunks(
|
||||
# UPLOAD_DIR, modelFilename, modelFilenameChunkNum, UPLOAD_DIR)
|
||||
# print(f'File saved to: {modelFilePath}')
|
||||
# configFilePath = os.path.join(UPLOAD_DIR, configFilename)
|
||||
|
||||
voiceChangerManager.loadModel(configFilePath, modelFilePath)
|
||||
return {"load": f"{modelFilePath}, {configFilePath}"}
|
||||
# voiceChangerManager.loadModel(configFilePath, modelFilePath)
|
||||
# return {"load": f"{modelFilePath}, {configFilePath}"}
|
||||
|
||||
@app_fastapi.post("/load_model_for_train")
|
||||
async def post_load_model_for_train(
|
||||
@ -184,49 +184,6 @@ if __name__ == thisFilename or args.colab == True:
|
||||
# Voice Changer
|
||||
# ##########
|
||||
|
||||
@app_fastapi.post("/test2")
|
||||
async def post_test2(voice: VoiceModel):
|
||||
try:
|
||||
# print("POST REQUEST PROCESSING....")
|
||||
gpu = voice.gpu
|
||||
srcId = voice.srcId
|
||||
dstId = voice.dstId
|
||||
timestamp = voice.timestamp
|
||||
prefixChunkSize = voice.prefixChunkSize
|
||||
buffer = voice.buffer
|
||||
wav = base64.b64decode(buffer)
|
||||
|
||||
if wav == 0:
|
||||
samplerate, data = read("dummy.wav")
|
||||
unpackedData = data
|
||||
else:
|
||||
unpackedData = np.array(struct.unpack(
|
||||
'<%sh' % (len(wav) // struct.calcsize('<h')), wav))
|
||||
# write("logs/received_data.wav", 24000,
|
||||
# unpackedData.astype(np.int16))
|
||||
|
||||
changedVoice = voiceChangerManager.changeVoice(
|
||||
gpu, srcId, dstId, timestamp, prefixChunkSize, unpackedData)
|
||||
|
||||
changedVoiceBase64 = base64.b64encode(changedVoice).decode('utf-8')
|
||||
data = {
|
||||
"gpu": gpu,
|
||||
"srcId": srcId,
|
||||
"dstId": dstId,
|
||||
"timestamp": timestamp,
|
||||
"prefixChunkSize": prefixChunkSize,
|
||||
"changedVoiceBase64": changedVoiceBase64
|
||||
}
|
||||
|
||||
json_compatible_item_data = jsonable_encoder(data)
|
||||
|
||||
return JSONResponse(content=json_compatible_item_data)
|
||||
|
||||
except Exception as e:
|
||||
print("REQUEST PROCESSING!!!! EXCEPTION!!!", e)
|
||||
print(traceback.format_exc())
|
||||
return str(e)
|
||||
|
||||
# Trainer REST API ※ ColabがTop直下のパスにしかPOSTを投げれないようなので"REST風"
|
||||
|
||||
@app_fastapi.get("/get_speakers")
|
||||
|
@ -7,7 +7,7 @@ from voice_changer.VoiceChangerManager import VoiceChangerManager
|
||||
|
||||
from restapi.MMVC_Rest_Hello import MMVC_Rest_Hello
|
||||
from restapi.MMVC_Rest_VoiceChanger import MMVC_Rest_VoiceChanger
|
||||
|
||||
from restapi.MMVC_Rest_Fileuploader import MMVC_Rest_Fileuploader
|
||||
class ValidationErrorLoggingRoute(APIRoute):
|
||||
def get_route_handler(self) -> Callable:
|
||||
original_route_handler = super().get_route_handler()
|
||||
@ -51,6 +51,8 @@ class MMVC_Rest:
|
||||
app_fastapi.include_router(restHello.router)
|
||||
restVoiceChanger = MMVC_Rest_VoiceChanger(voiceChangerManager)
|
||||
app_fastapi.include_router(restVoiceChanger.router)
|
||||
fileUploader = MMVC_Rest_Fileuploader(voiceChangerManager)
|
||||
app_fastapi.include_router(fileUploader.router)
|
||||
|
||||
cls._instance = app_fastapi
|
||||
return cls._instance
|
||||
|
40
server/restapi/MMVC_Rest_Fileuploader.py
Normal file
40
server/restapi/MMVC_Rest_Fileuploader.py
Normal file
@ -0,0 +1,40 @@
|
||||
import os
|
||||
|
||||
from fastapi import APIRouter
|
||||
from fastapi.encoders import jsonable_encoder
|
||||
from fastapi.responses import JSONResponse
|
||||
from fastapi import HTTPException, FastAPI, UploadFile, File, Form
|
||||
|
||||
from mods.FileUploader import upload_file, concat_file_chunks
|
||||
from voice_changer.VoiceChangerManager import VoiceChangerManager
|
||||
|
||||
UPLOAD_DIR = "upload_dir"
|
||||
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
||||
MODEL_DIR = "MMVC_Trainer/logs"
|
||||
os.makedirs(MODEL_DIR, exist_ok=True)
|
||||
|
||||
class MMVC_Rest_Fileuploader:
|
||||
def __init__(self, voiceChangerManager:VoiceChangerManager):
|
||||
self.voiceChangerManager = voiceChangerManager
|
||||
self.router = APIRouter()
|
||||
self.router.add_api_route("/upload_file", self.post_upload_file, methods=["POST"])
|
||||
self.router.add_api_route("/load_model", self.post_load_model, methods=["POST"])
|
||||
|
||||
def post_upload_file(self, file: UploadFile = File(...), filename: str = Form(...)):
|
||||
return upload_file(UPLOAD_DIR, file, filename)
|
||||
|
||||
def post_load_model(
|
||||
self,
|
||||
modelFilename: str = Form(...),
|
||||
modelFilenameChunkNum: int = Form(...),
|
||||
configFilename: str = Form(...)
|
||||
):
|
||||
modelFilePath = concat_file_chunks(
|
||||
UPLOAD_DIR, modelFilename, modelFilenameChunkNum, UPLOAD_DIR)
|
||||
configFilePath = os.path.join(UPLOAD_DIR, configFilename)
|
||||
|
||||
self.voiceChangerManager.loadModel(configFilePath, modelFilePath)
|
||||
return {"load": f"{modelFilePath}, {configFilePath}"}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user