diff --git a/app/asr_models/asr_model.py b/app/asr_models/asr_model.py index 8c625ecf2e8717f5b4f8776db47ede1a71a2ff9f..76b7b8551d7dbf7fae72092297b314c4e25df096 100644 --- a/app/asr_models/asr_model.py +++ b/app/asr_models/asr_model.py @@ -19,7 +19,8 @@ class ASRModel(ABC): last_activity_time = time.time() def __init__(self): - pass + # Flag indicating if a transcription is currently running + self.transcription_active = False @abstractmethod def load_model(self): diff --git a/app/asr_models/faster_whisper_engine.py b/app/asr_models/faster_whisper_engine.py index d7c3c44fb9352857ab5222fd59075a80e5e832ad..3c9c8b53c0228e1b02951c814dad5e245a8d6198 100644 --- a/app/asr_models/faster_whisper_engine.py +++ b/app/asr_models/faster_whisper_engine.py @@ -35,6 +35,9 @@ class FasterWhisperASR(ASRModel): options: Union[dict, None], output, ): + # Mark transcription as active + self.transcription_active = True + # Update last activity timestamp self.last_activity_time = time.time() with self.model_lock: @@ -62,6 +65,8 @@ class FasterWhisperASR(ASRModel): output_file = StringIO() self.write_result(result, output_file, output) output_file.seek(0) + # Mark transcription as completed + self.transcription_active = False return output_file diff --git a/app/asr_models/mbain_whisperx_engine.py b/app/asr_models/mbain_whisperx_engine.py index 87494a3c788dc7a31c2c548e948a901d8041919f..458b5bc4c7ad77b3a86352d915b683d7d8cfc5a3 100644 --- a/app/asr_models/mbain_whisperx_engine.py +++ b/app/asr_models/mbain_whisperx_engine.py @@ -48,6 +48,9 @@ class WhisperXASR(ASRModel): options: Union[dict, None], output, ): + # Mark transcription as active + self.transcription_active = True + # Update last activity timestamp self.last_activity_time = time.time() with self.model_lock: if self.model is None: @@ -88,6 +91,8 @@ class WhisperXASR(ASRModel): output_file = StringIO() self.write_result(result, output_file, output) output_file.seek(0) + # Mark transcription as completed + self.transcription_active = False return output_file diff --git a/app/asr_models/openai_whisper_engine.py b/app/asr_models/openai_whisper_engine.py index 655d682bd26f12f9de67ed1b6fdd7253e718bd22..a82ec7fdbcf36abeacd325d48047c1d03d26a489 100644 --- a/app/asr_models/openai_whisper_engine.py +++ b/app/asr_models/openai_whisper_engine.py @@ -33,6 +33,9 @@ class OpenAIWhisperASR(ASRModel): options: Union[dict, None], output, ): + # Mark transcription as active + self.transcription_active = True + # Update last activity timestamp self.last_activity_time = time.time() with self.model_lock: @@ -52,6 +55,8 @@ class OpenAIWhisperASR(ASRModel): output_file = StringIO() self.write_result(result, output_file, output) output_file.seek(0) + # Mark transcription as completed + self.transcription_active = False return output_file diff --git a/app/webservice.py b/app/webservice.py index 8f4fa6a3f65dc714b9dad4a122d8a0dadc816b3d..24fe05daf30a25bcc323b4754f59fbff582cb918 100644 --- a/app/webservice.py +++ b/app/webservice.py @@ -119,6 +119,13 @@ async def detect_language( "language_code": detected_lang_code, "confidence": confidence, } + +@app.get("/transcription/status", tags=["Endpoints"]) +async def transcription_status(): + """ + Return whether a transcription is currently running. + """ + return {"active": asr_model.transcription_active} @click.command()