Skip to content
Snippets Groups Projects
Commit f8f7a28c authored by Subliminal Guy's avatar Subliminal Guy
Browse files

Add transcription status route

parent 5ee9169f
No related branches found
No related tags found
No related merge requests found
...@@ -19,7 +19,8 @@ class ASRModel(ABC): ...@@ -19,7 +19,8 @@ class ASRModel(ABC):
last_activity_time = time.time() last_activity_time = time.time()
def __init__(self): def __init__(self):
pass # Flag indicating if a transcription is currently running
self.transcription_active = False
@abstractmethod @abstractmethod
def load_model(self): def load_model(self):
......
...@@ -35,6 +35,9 @@ class FasterWhisperASR(ASRModel): ...@@ -35,6 +35,9 @@ class FasterWhisperASR(ASRModel):
options: Union[dict, None], options: Union[dict, None],
output, output,
): ):
# Mark transcription as active
self.transcription_active = True
# Update last activity timestamp
self.last_activity_time = time.time() self.last_activity_time = time.time()
with self.model_lock: with self.model_lock:
...@@ -62,6 +65,8 @@ class FasterWhisperASR(ASRModel): ...@@ -62,6 +65,8 @@ class FasterWhisperASR(ASRModel):
output_file = StringIO() output_file = StringIO()
self.write_result(result, output_file, output) self.write_result(result, output_file, output)
output_file.seek(0) output_file.seek(0)
# Mark transcription as completed
self.transcription_active = False
return output_file return output_file
......
...@@ -48,6 +48,9 @@ class WhisperXASR(ASRModel): ...@@ -48,6 +48,9 @@ class WhisperXASR(ASRModel):
options: Union[dict, None], options: Union[dict, None],
output, output,
): ):
# Mark transcription as active
self.transcription_active = True
# Update last activity timestamp
self.last_activity_time = time.time() self.last_activity_time = time.time()
with self.model_lock: with self.model_lock:
if self.model is None: if self.model is None:
...@@ -88,6 +91,8 @@ class WhisperXASR(ASRModel): ...@@ -88,6 +91,8 @@ class WhisperXASR(ASRModel):
output_file = StringIO() output_file = StringIO()
self.write_result(result, output_file, output) self.write_result(result, output_file, output)
output_file.seek(0) output_file.seek(0)
# Mark transcription as completed
self.transcription_active = False
return output_file return output_file
......
...@@ -33,6 +33,9 @@ class OpenAIWhisperASR(ASRModel): ...@@ -33,6 +33,9 @@ class OpenAIWhisperASR(ASRModel):
options: Union[dict, None], options: Union[dict, None],
output, output,
): ):
# Mark transcription as active
self.transcription_active = True
# Update last activity timestamp
self.last_activity_time = time.time() self.last_activity_time = time.time()
with self.model_lock: with self.model_lock:
...@@ -52,6 +55,8 @@ class OpenAIWhisperASR(ASRModel): ...@@ -52,6 +55,8 @@ class OpenAIWhisperASR(ASRModel):
output_file = StringIO() output_file = StringIO()
self.write_result(result, output_file, output) self.write_result(result, output_file, output)
output_file.seek(0) output_file.seek(0)
# Mark transcription as completed
self.transcription_active = False
return output_file return output_file
......
...@@ -120,6 +120,13 @@ async def detect_language( ...@@ -120,6 +120,13 @@ async def detect_language(
"confidence": confidence, "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() @click.command()
@click.option( @click.option(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment