diff --git a/.gitignore b/.gitignore index 7a24b88..e6e1ec1 100644 --- a/.gitignore +++ b/.gitignore @@ -284,4 +284,4 @@ rolegenie/media/ templates.py newrelic.ini __pycache__/ -audios/* \ No newline at end of file +audios/ \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 127412e..40d0ac0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -34,7 +34,7 @@ nvidia-cusolver-cu11==11.4.0.1 nvidia-cusparse-cu11==11.7.4.91 nvidia-nccl-cu11==2.14.3 nvidia-nvtx-cu11==11.7.91 -openai-whisper==20230314 +openai-whisper==20231117 python-dotenv==1.0.0 regex==2023.6.3 requests==2.31.0 diff --git a/routes.py b/routes.py index be3f79c..06f3c7b 100644 --- a/routes.py +++ b/routes.py @@ -1,3 +1,4 @@ +import os import uuid import json @@ -29,8 +30,10 @@ async def transcribe(request): status_code=400, content={"status": 400, "message": "Bad Request", "data": {}}, ) - - file_path = f"{str(ROOT_DIR)}/audios/{str(uuid.uuid4())}.mp3" + audio_directory = f"{str(ROOT_DIR)}/audios" + if not os.path.exists(audio_directory): + os.makedirs(audio_directory) + file_path = f"{audio_directory}/{str(uuid.uuid4())}.mp3" with open(file_path, "wb") as f: f.write(audio.file.read()) diff --git a/routes_definition/transcribe/transcribe.py b/routes_definition/transcribe/transcribe.py index d2e259e..6808075 100644 --- a/routes_definition/transcribe/transcribe.py +++ b/routes_definition/transcribe/transcribe.py @@ -1,8 +1,10 @@ +import os import whisper def transcribe_helper(model: whisper.Whisper, audio_path: str, language: str): result = model.transcribe(audio_path, language=language) + os.remove(audio_path) print(result) return result["text"]