Spaces:
Running
Running
jhj0517
commited on
Commit
·
6f6c89b
1
Parent(s):
51a408d
Apply `add_timestamp` in caching
Browse files
modules/whisper/whisper_base.py
CHANGED
@@ -62,7 +62,8 @@ class WhisperBase(ABC):
|
|
62 |
|
63 |
def run(self,
|
64 |
audio: Union[str, BinaryIO, np.ndarray],
|
65 |
-
progress: gr.Progress,
|
|
|
66 |
*whisper_params,
|
67 |
) -> Tuple[List[dict], float]:
|
68 |
"""
|
@@ -76,6 +77,8 @@ class WhisperBase(ABC):
|
|
76 |
Audio input. This can be file path or binary type.
|
77 |
progress: gr.Progress
|
78 |
Indicator to show progress directly in gradio.
|
|
|
|
|
79 |
*whisper_params: tuple
|
80 |
Parameters related with whisper. This will be dealt with "WhisperParameters" data class
|
81 |
|
@@ -88,14 +91,17 @@ class WhisperBase(ABC):
|
|
88 |
"""
|
89 |
params = WhisperParameters.as_value(*whisper_params)
|
90 |
|
|
|
|
|
|
|
|
|
|
|
91 |
if params.lang == "Automatic Detection":
|
92 |
params.lang = None
|
93 |
else:
|
94 |
language_code_dict = {value: key for key, value in whisper.tokenizer.LANGUAGES.items()}
|
95 |
params.lang = language_code_dict[params.lang]
|
96 |
|
97 |
-
self.cache_parameters(params)
|
98 |
-
|
99 |
speech_chunks = None
|
100 |
if params.vad_filter:
|
101 |
# Explicit value set for float('inf') from gr.Number()
|
@@ -181,6 +187,7 @@ class WhisperBase(ABC):
|
|
181 |
transcribed_segments, time_for_task = self.run(
|
182 |
file.name,
|
183 |
progress,
|
|
|
184 |
*whisper_params,
|
185 |
)
|
186 |
|
@@ -304,6 +311,7 @@ class WhisperBase(ABC):
|
|
304 |
transcribed_segments, time_for_task = self.run(
|
305 |
audio,
|
306 |
progress,
|
|
|
307 |
*whisper_params,
|
308 |
)
|
309 |
|
@@ -439,9 +447,13 @@ class WhisperBase(ABC):
|
|
439 |
os.remove(file_path)
|
440 |
|
441 |
@staticmethod
|
442 |
-
def cache_parameters(
|
|
|
|
|
|
|
443 |
cached_params = load_yaml(DEFAULT_PARAMETERS_CONFIG_PATH)
|
444 |
cached_whisper_param = whisper_params.to_yaml()
|
445 |
cached_yaml = {**cached_params, **cached_whisper_param}
|
|
|
446 |
|
447 |
save_yaml(cached_yaml, DEFAULT_PARAMETERS_CONFIG_PATH)
|
|
|
62 |
|
63 |
def run(self,
|
64 |
audio: Union[str, BinaryIO, np.ndarray],
|
65 |
+
progress: gr.Progress = gr.Progress(),
|
66 |
+
add_timestamp: bool = True,
|
67 |
*whisper_params,
|
68 |
) -> Tuple[List[dict], float]:
|
69 |
"""
|
|
|
77 |
Audio input. This can be file path or binary type.
|
78 |
progress: gr.Progress
|
79 |
Indicator to show progress directly in gradio.
|
80 |
+
add_timestamp: bool
|
81 |
+
Whether to add a timestamp at the end of the filename.
|
82 |
*whisper_params: tuple
|
83 |
Parameters related with whisper. This will be dealt with "WhisperParameters" data class
|
84 |
|
|
|
91 |
"""
|
92 |
params = WhisperParameters.as_value(*whisper_params)
|
93 |
|
94 |
+
self.cache_parameters(
|
95 |
+
whisper_params=params,
|
96 |
+
add_timestamp=add_timestamp
|
97 |
+
)
|
98 |
+
|
99 |
if params.lang == "Automatic Detection":
|
100 |
params.lang = None
|
101 |
else:
|
102 |
language_code_dict = {value: key for key, value in whisper.tokenizer.LANGUAGES.items()}
|
103 |
params.lang = language_code_dict[params.lang]
|
104 |
|
|
|
|
|
105 |
speech_chunks = None
|
106 |
if params.vad_filter:
|
107 |
# Explicit value set for float('inf') from gr.Number()
|
|
|
187 |
transcribed_segments, time_for_task = self.run(
|
188 |
file.name,
|
189 |
progress,
|
190 |
+
add_timestamp,
|
191 |
*whisper_params,
|
192 |
)
|
193 |
|
|
|
311 |
transcribed_segments, time_for_task = self.run(
|
312 |
audio,
|
313 |
progress,
|
314 |
+
add_timestamp,
|
315 |
*whisper_params,
|
316 |
)
|
317 |
|
|
|
447 |
os.remove(file_path)
|
448 |
|
449 |
@staticmethod
|
450 |
+
def cache_parameters(
|
451 |
+
whisper_params: WhisperValues,
|
452 |
+
add_timestamp: bool
|
453 |
+
):
|
454 |
cached_params = load_yaml(DEFAULT_PARAMETERS_CONFIG_PATH)
|
455 |
cached_whisper_param = whisper_params.to_yaml()
|
456 |
cached_yaml = {**cached_params, **cached_whisper_param}
|
457 |
+
cached_yaml["whisper"]["add_timestamp"] = add_timestamp
|
458 |
|
459 |
save_yaml(cached_yaml, DEFAULT_PARAMETERS_CONFIG_PATH)
|