Support loading hf models

Signed-off-by: makaveli10 <vineet.suryan@collabora.com>
This commit is contained in:
makaveli10
2024-11-26 11:14:18 +05:30
parent 446fc6e835
commit 2eff360b9e
2 changed files with 41 additions and 30 deletions
+1 -1
View File
@@ -87,7 +87,7 @@ client = TranscriptionClient(
9090, 9090,
lang="en", lang="en",
translate=False, translate=False,
model="small", model="small", # also support hf_model => `Systran/faster-whisper-small`
use_vad=False, use_vad=False,
save_output_recording=True, # Only used for microphone input, False by Default save_output_recording=True, # Only used for microphone input, False by Default
output_recording_filename="./output_recording.wav", # Only used for microphone input output_recording_filename="./output_recording.wav", # Only used for microphone input
+14 -3
View File
@@ -181,6 +181,7 @@ class TranscriptionServer:
})) }))
self.backend = BackendType.FASTER_WHISPER self.backend = BackendType.FASTER_WHISPER
try:
if self.backend.is_faster_whisper(): if self.backend.is_faster_whisper():
if faster_whisper_custom_model_path is not None and os.path.exists(faster_whisper_custom_model_path): if faster_whisper_custom_model_path is not None and os.path.exists(faster_whisper_custom_model_path):
logging.info(f"Using custom model {faster_whisper_custom_model_path}") logging.info(f"Using custom model {faster_whisper_custom_model_path}")
@@ -196,7 +197,10 @@ class TranscriptionServer:
use_vad=self.use_vad, use_vad=self.use_vad,
single_model=self.single_model, single_model=self.single_model,
) )
logging.info("Running faster_whisper backend.") logging.info("Running faster_whisper backend.")
except Exception as e:
return
if client is None: if client is None:
raise ValueError(f"Backend type {self.backend.value} not recognised or not handled.") raise ValueError(f"Backend type {self.backend.value} not recognised or not handled.")
@@ -785,9 +789,6 @@ class ServeClientFasterWhisper(ServeClientBase):
"large-v3-turbo", "turbo" "large-v3-turbo", "turbo"
] ]
if not os.path.exists(model):
self.model_size_or_path = self.check_valid_model(model)
else:
self.model_size_or_path = model self.model_size_or_path = model
self.language = "en" if self.model_size_or_path.endswith("en") else language self.language = "en" if self.model_size_or_path.endswith("en") else language
self.task = task self.task = task
@@ -807,6 +808,7 @@ class ServeClientFasterWhisper(ServeClientBase):
return return
logging.info(f"Using Device={device} with precision {self.compute_type}") logging.info(f"Using Device={device} with precision {self.compute_type}")
try:
if single_model: if single_model:
if ServeClientFasterWhisper.SINGLE_MODEL is None: if ServeClientFasterWhisper.SINGLE_MODEL is None:
self.create_model(device) self.create_model(device)
@@ -815,6 +817,15 @@ class ServeClientFasterWhisper(ServeClientBase):
self.transcriber = ServeClientFasterWhisper.SINGLE_MODEL self.transcriber = ServeClientFasterWhisper.SINGLE_MODEL
else: else:
self.create_model(device) self.create_model(device)
except Exception as e:
logging.error(f"Failed to load model: {e}")
self.websocket.send(json.dumps({
"uid": self.client_uid,
"status": "ERROR",
"message": f"Failed to load model: {str(self.model_size_or_path)}"
}))
self.websocket.close()
return
self.use_vad = use_vad self.use_vad = use_vad