From 0faaf0f3011e5bda160f9c811325b87ff0e89c61 Mon Sep 17 00:00:00 2001 From: heimoshuiyu Date: Fri, 13 Sep 2024 16:21:35 +0800 Subject: [PATCH] support translate endpoint --- whisper_fastapi.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/whisper_fastapi.py b/whisper_fastapi.py index 60eac76..77786e3 100644 --- a/whisper_fastapi.py +++ b/whisper_fastapi.py @@ -298,10 +298,11 @@ async def translateapi( @app.post("/v1/audio/transcriptions") @app.post("/v1/audio/translations") async def transcription( + request: Request, file: UploadFile = File(...), prompt: str = Form(""), response_format: str = Form("json"), - task: str = Form("transcribe"), + task: str = Form(""), language: str = Form("und"), vad_filter: bool = Form(False), repetition_penalty: float = Form(1.0), @@ -311,6 +312,14 @@ async def transcription( User upload audio file in multipart/form-data format and receive transcription in response """ + if not task: + if request.url.path == '/v1/audio/transcriptions': + task = "transcribe" + elif request.url.path == '/v1/audio/translations': + task = "translate" + else: + raise HTTPException(400, "task parameter is required") + # timestamp as filename, keep original extension generator, info = stream_builder( audio=io.BytesIO(file.file.read()),