forked from saharmor/whisper-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhanced codebase clarity and adhered to best practices by significan…
…tly reducing the reliance on plain strings. Implemented data type indicators in functions handling audio data, incorporated assertions for audio data types, and transformed ClientState into an enum for improved representation. Whisper model sizes are now exclusively utilized as enum elements. Additionally, introduced a Whisper model cache to enable swift transcription startup, eliminating the requirement for model reloading. Fixed bug where the client's Whisper model size list didn't match the server's supported model sizes list. Fixed bug where "No more clients allowed" error doesn't appear correctly in client.
- Loading branch information
Showing
12 changed files
with
177 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from config import WhisperModelSize | ||
from faster_whisper import WhisperModel | ||
import logging | ||
|
||
|
||
class ModelCache: | ||
_downloaded_models = {} | ||
|
||
@classmethod | ||
def add_downloaded_model(cls, model_size: WhisperModelSize, model: WhisperModel): | ||
cls._downloaded_models[model_size] = model | ||
logging.info(f"{model_size} added to cache") | ||
|
||
@classmethod | ||
def is_model_downloaded(cls, model_size: WhisperModelSize): | ||
return model_size in cls._downloaded_models.keys() | ||
|
||
@classmethod | ||
def get_model(cls, model_size: WhisperModelSize): | ||
try: | ||
model = cls._downloaded_models[model_size] | ||
logging.info(f"{model_size} retrieved from cache") | ||
return model | ||
except KeyError: | ||
return None |
Oops, something went wrong.