From 281b3cabc15770258793aa41a444bcac0c97a766 Mon Sep 17 00:00:00 2001 From: Karl Date: Sat, 13 Jul 2024 09:56:21 +0000 Subject: [PATCH] more cleanup --- .vscode/launch.json | 7 +++++-- bazarr-ai-sub-generator/cli.py | 1 - bazarr-ai-sub-generator/main.py | 21 +++------------------ bazarr-ai-sub-generator/utils/decorator.py | 13 +++++++++++++ requirements.txt | 1 - setup.py | 1 - 6 files changed, 21 insertions(+), 23 deletions(-) create mode 100644 bazarr-ai-sub-generator/utils/decorator.py diff --git a/.vscode/launch.json b/.vscode/launch.json index 6cacf66..ccbc084 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,12 +11,15 @@ "program": "${file}", "console": "integratedTerminal", "justMyCode": false, + "env": { + "CUDA_VISIBLE_DEVICES": "1" + }, "args": [ "--model", "base", "--show", "Gary Neville's Soccerbox" - ], + ] } ] -} \ No newline at end of file +} diff --git a/bazarr-ai-sub-generator/cli.py b/bazarr-ai-sub-generator/cli.py index 8780f82..ad22bf6 100644 --- a/bazarr-ai-sub-generator/cli.py +++ b/bazarr-ai-sub-generator/cli.py @@ -77,7 +77,6 @@ def main(): "--show", type=str, default=None, - #choices=["transcribe", "translate"], help="whether to perform X->X speech recognition ('transcribe') \ or X->English translation ('translate')", ) diff --git a/bazarr-ai-sub-generator/main.py b/bazarr-ai-sub-generator/main.py index 2fe1ba3..76d009b 100644 --- a/bazarr-ai-sub-generator/main.py +++ b/bazarr-ai-sub-generator/main.py @@ -7,27 +7,14 @@ from utils.ffmpeg import get_audio, add_subtitles_to_mp4 from utils.bazarr import get_wanted_episodes, get_episode_details, sync_series from utils.sonarr import update_show_in_sonarr from utils.whisper import WhisperAI - -def measure_time(func): - def wrapper(*args, **kwargs): - start_time = time.time() - result = func(*args, **kwargs) - end_time = time.time() - duration = end_time - start_time - print(f"Function '{func.__name__}' executed in: {duration:.6f} seconds") - return result - return wrapper - - +from utils.decorator import measure_time def process(args: dict): model_name: str = args.pop("model") language: str = args.pop("language") show: str = args.pop("show") - # sample_interval: str = args.pop("sample_interval") - # audio_channel: str = args.pop("audio_channel") - + if model_name.endswith(".en"): warnings.warn( f"{model_name} is an English-only model, forcing English detection." @@ -38,10 +25,8 @@ def process(args: dict): args["language"] = language model_args = {} - # model_args["model_size_or_path"] = model_name model_args["device"] = args.pop("device") - # model_args["compute_type"] = args.pop("compute_type") - + list_of_episodes_needing_subtitles = get_wanted_episodes(show) print( f"Found {list_of_episodes_needing_subtitles['total']} episodes needing subtitles." diff --git a/bazarr-ai-sub-generator/utils/decorator.py b/bazarr-ai-sub-generator/utils/decorator.py new file mode 100644 index 0000000..d06a988 --- /dev/null +++ b/bazarr-ai-sub-generator/utils/decorator.py @@ -0,0 +1,13 @@ +import time +from datetime import timedelta + +def measure_time(func): + def wrapper(*args, **kwargs): + start_time = time.time() + result = func(*args, **kwargs) + end_time = time.time() + duration = end_time - start_time + human_readable_duration = str(timedelta(seconds=duration)) + print(f"Function '{func.__name__}' executed in: {human_readable_duration}") + return result + return wrapper diff --git a/requirements.txt b/requirements.txt index ec34ef1..755a1a7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ -faster-whisper==0.10.0 tqdm==4.56.0 ffmpeg-python==0.2.0 git+https://github.com/openai/whisper.git diff --git a/setup.py b/setup.py index 337aa84..96873f9 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,6 @@ setup( py_modules=["bazarr-ai-sub-generator"], author="Karl Hudgell", install_requires=[ - 'faster-whisper', 'tqdm', 'ffmpeg-python' ],