From ad0c3eea66a1aeb870ba4feed0824e4d032ad98c Mon Sep 17 00:00:00 2001 From: lebaudantoine Date: Tue, 3 Dec 2024 19:09:42 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9(summary)=20remove=20temporary=20au?= =?UTF-8?q?dio=20files=20saved?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I forgot to remove temporary files downloaded from the Minio bucket. --- src/summary/summary/core/celery_worker.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/summary/summary/core/celery_worker.py b/src/summary/summary/core/celery_worker.py index b45bdd41..3fcda952 100644 --- a/src/summary/summary/core/celery_worker.py +++ b/src/summary/summary/core/celery_worker.py @@ -1,6 +1,7 @@ """Celery workers.""" import json +import os import tempfile from pathlib import Path @@ -28,6 +29,7 @@ celery = Celery( ) if settings.sentry_dsn and settings.sentry_is_enabled: + @signals.celeryd_init.connect def init_sentry(**_kwargs): """Initialize sentry.""" @@ -100,15 +102,20 @@ def process_audio_transcribe_summarize(filename: str, email: str, sub: str): api_key=settings.openai_api_key, base_url=settings.openai_base_url ) - logger.debug("Querying transcription …") - with open(temp_file_path, "rb") as audio_file: - transcription = openai_client.audio.transcriptions.create( - model=settings.openai_asr_model, file=audio_file - ) + try: + logger.debug("Querying transcription …") + with open(temp_file_path, "rb") as audio_file: + transcription = openai_client.audio.transcriptions.create( + model=settings.openai_asr_model, file=audio_file + ) - transcription = transcription.text + transcription = transcription.text - logger.debug("Transcription: \n %s", transcription) + logger.debug("Transcription: \n %s", transcription) + finally: + if os.path.exists(temp_file_path): + os.remove(temp_file_path) + logger.debug("Temporary file removed: %s", temp_file_path) instructions = get_instructions(transcription) summary_response = openai_client.chat.completions.create(