fix file uploads

This commit is contained in:
James S 2024-03-31 21:35:19 +00:00
parent 6a5c071fe1
commit b9bdf1b86e
2 changed files with 7 additions and 6 deletions

12
api.py
View File

@ -1,11 +1,11 @@
from fastapi import FastAPI, Response, UploadFile from fastapi import FastAPI, File, Query, Response, UploadFile
from fastapi.encoders import jsonable_encoder from fastapi.encoders import jsonable_encoder
from fastapi.responses import FileResponse from fastapi.responses import FileResponse
from config import TOKEN from config import TOKEN
import hmac import hmac
import model import model
from pydantic import BaseModel from pydantic import BaseModel
from typing import List, Optional from typing import Annotated, List, Optional
import tempfile import tempfile
from rvc.main import song_cover_pipeline from rvc.main import song_cover_pipeline
@ -33,16 +33,16 @@ async def root(token: str,
@app.post("/rvc") @app.post("/rvc")
async def rvc(token: str, async def rvc(token: str,
file: UploadFile, file: Annotated[bytes, File()],
response: Response, response: Response,
pitch_change_oct: Optional[int] = 1, pitch_change_oct: Annotated[int, Query()] = 1,
pitch_change_sem: Optional[int] = 0): pitch_change_sem: Annotated[int, Query()] = 0):
if not hmac.compare_digest(token, TOKEN): if not hmac.compare_digest(token, TOKEN):
response.status_code = 401 response.status_code = 401
return {"error": "Bad token"} return {"error": "Bad token"}
with tempfile.NamedTemporaryFile() as tmp: with tempfile.NamedTemporaryFile() as tmp:
tmp.write(await file.read()) tmp.write(file)
ai_vocals_path = song_cover_pipeline(tmp.name, pitch_change_oct, voice_model='miku', pitch_change_sem=pitch_change_sem) ai_vocals_path = song_cover_pipeline(tmp.name, pitch_change_oct, voice_model='miku', pitch_change_sem=pitch_change_sem)
return FileResponse(ai_vocals_path) return FileResponse(ai_vocals_path)

View File

@ -9,6 +9,7 @@ onnxruntime_gpu
praat-parselmouth>=0.4.2 praat-parselmouth>=0.4.2
#pedalboard==0.7.7 #pedalboard==0.7.7
#pydub==0.25.1 #pydub==0.25.1
python-multipart==0.0.9
pyworld==0.3.4 pyworld==0.3.4
#Requests==2.31.0 #Requests==2.31.0
scipy==1.11.1 scipy==1.11.1