From 9ee821ab18f15ed6171304ac55e8a27b0fa3057e Mon Sep 17 00:00:00 2001 From: jhj0517 <97279763+jhj0517@users.noreply.github.com> Date: Sat, 23 Nov 2024 12:49:52 +0900 Subject: [PATCH 1/6] Allow custom values --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 9b529b8..bd24337 100644 --- a/app.py +++ b/app.py @@ -49,7 +49,7 @@ def create_pipeline_inputs(self): with gr.Row(): dd_model = gr.Dropdown(choices=self.whisper_inf.available_models, value=whisper_params["model_size"], - label=_("Model")) + label=_("Model"), allow_custom_value=True) dd_lang = gr.Dropdown(choices=self.whisper_inf.available_langs + [AUTOMATIC_DETECTION], value=AUTOMATIC_DETECTION if whisper_params["lang"] == AUTOMATIC_DETECTION.unwrap() else whisper_params["lang"], label=_("Language")) From c8e1c0f0e3fb1eacbfebe259c53ec597b09d3b06 Mon Sep 17 00:00:00 2001 From: jhj0517 <97279763+jhj0517@users.noreply.github.com> Date: Sat, 23 Nov 2024 12:50:30 +0900 Subject: [PATCH 2/6] Enable direct use from hf model --- modules/whisper/faster_whisper_inference.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/whisper/faster_whisper_inference.py b/modules/whisper/faster_whisper_inference.py index e497f9b..2eac499 100644 --- a/modules/whisper/faster_whisper_inference.py +++ b/modules/whisper/faster_whisper_inference.py @@ -1,5 +1,6 @@ import os import time +import huggingface_hub import numpy as np import torch from typing import BinaryIO, Union, Tuple, List @@ -126,6 +127,14 @@ def update_model(self, Indicator to show progress directly in gradio. """ progress(0, desc="Initializing Model..") + + if model_size not in self.model_paths: + huggingface_hub.snapshot_download(model_size, + cache_dir=self.model_dir, + local_dir=os.path.join(self.model_dir, model_size) + ) + self.model_paths = self.get_model_paths() + self.current_model_size = self.model_paths[model_size] local_files_only = False From bf48906b727bf977b25fd9d2e38890648289f69e Mon Sep 17 00:00:00 2001 From: jhj0517 <97279763+jhj0517@users.noreply.github.com> Date: Sat, 23 Nov 2024 12:50:48 +0900 Subject: [PATCH 3/6] Fix windows path bug --- modules/whisper/faster_whisper_inference.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/whisper/faster_whisper_inference.py b/modules/whisper/faster_whisper_inference.py index 2eac499..066a487 100644 --- a/modules/whisper/faster_whisper_inference.py +++ b/modules/whisper/faster_whisper_inference.py @@ -131,7 +131,7 @@ def update_model(self, if model_size not in self.model_paths: huggingface_hub.snapshot_download(model_size, cache_dir=self.model_dir, - local_dir=os.path.join(self.model_dir, model_size) + local_dir=os.path.join(self.model_dir, model_size.replace("/", "_")) ) self.model_paths = self.get_model_paths() From f5c4e6123056f25c82200798da1554446f5a75bc Mon Sep 17 00:00:00 2001 From: jhj0517 <97279763+jhj0517@users.noreply.github.com> Date: Sat, 23 Nov 2024 13:14:42 +0900 Subject: [PATCH 4/6] Update model path logic for incorrect character `/` --- modules/whisper/faster_whisper_inference.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/modules/whisper/faster_whisper_inference.py b/modules/whisper/faster_whisper_inference.py index 066a487..6dc1cbf 100644 --- a/modules/whisper/faster_whisper_inference.py +++ b/modules/whisper/faster_whisper_inference.py @@ -128,14 +128,18 @@ def update_model(self, """ progress(0, desc="Initializing Model..") - if model_size not in self.model_paths: - huggingface_hub.snapshot_download(model_size, - cache_dir=self.model_dir, - local_dir=os.path.join(self.model_dir, model_size.replace("/", "_")) - ) + model_size_dirname = model_size.replace("/", "--") if "/" in model_size else model_size + if model_size not in self.model_paths and model_size_dirname not in self.model_paths: + print(f"Model is not detected. Trying to download \"{model_size}\" from huggingface to " + f"\"{os.path.join(self.model_dir, model_size_dirname)} ...") + huggingface_hub.snapshot_download( + model_size, + cache_dir=self.model_dir, + local_dir=os.path.join(self.model_dir, model_size_dirname) + ) self.model_paths = self.get_model_paths() - self.current_model_size = self.model_paths[model_size] + self.current_model_size = self.model_paths[model_size_dirname] local_files_only = False hf_prefix = "models--Systran--faster-whisper-" From 82add6985b1c3e311529c8cb4ac2050fc7dc6ae1 Mon Sep 17 00:00:00 2001 From: jhj0517 <97279763+jhj0517@users.noreply.github.com> Date: Sat, 23 Nov 2024 17:57:46 +0900 Subject: [PATCH 5/6] Update docstring --- modules/whisper/faster_whisper_inference.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/whisper/faster_whisper_inference.py b/modules/whisper/faster_whisper_inference.py index 6dc1cbf..d967a10 100644 --- a/modules/whisper/faster_whisper_inference.py +++ b/modules/whisper/faster_whisper_inference.py @@ -119,7 +119,8 @@ def update_model(self, Parameters ---------- model_size: str - Size of whisper model + Size of whisper model. If you enter the huggingface repo id, it will try to download the model + automatically from huggingface. compute_type: str Compute type for transcription. see more info : https://opennmt.net/CTranslate2/quantization.html From 5a11504f4b1378eac7971f28666079383cefe449 Mon Sep 17 00:00:00 2001 From: jhj0517 <97279763+jhj0517@users.noreply.github.com> Date: Sat, 23 Nov 2024 19:50:53 +0900 Subject: [PATCH 6/6] Remove meaningless `cache_dir` and add `gr.Info` dialogue --- modules/whisper/faster_whisper_inference.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/whisper/faster_whisper_inference.py b/modules/whisper/faster_whisper_inference.py index d967a10..4946985 100644 --- a/modules/whisper/faster_whisper_inference.py +++ b/modules/whisper/faster_whisper_inference.py @@ -135,10 +135,10 @@ def update_model(self, f"\"{os.path.join(self.model_dir, model_size_dirname)} ...") huggingface_hub.snapshot_download( model_size, - cache_dir=self.model_dir, - local_dir=os.path.join(self.model_dir, model_size_dirname) + local_dir=os.path.join(self.model_dir, model_size_dirname), ) self.model_paths = self.get_model_paths() + gr.Info(f"Model is downloaded with the name \"{model_size_dirname}\"") self.current_model_size = self.model_paths[model_size_dirname]