Spaces:
Running
Running
jhj0517
commited on
Commit
·
482e6f7
1
Parent(s):
320b77a
Use wirter options to highlight
Browse files
modules/whisper/base_transcription_pipeline.py
CHANGED
|
@@ -178,7 +178,7 @@ class BaseTranscriptionPipeline(ABC):
|
|
| 178 |
file_format: str = "SRT",
|
| 179 |
add_timestamp: bool = True,
|
| 180 |
progress=gr.Progress(),
|
| 181 |
-
*
|
| 182 |
) -> list:
|
| 183 |
"""
|
| 184 |
Write subtitle file from Files
|
|
@@ -196,7 +196,7 @@ class BaseTranscriptionPipeline(ABC):
|
|
| 196 |
Boolean value from gr.Checkbox() that determines whether to add a timestamp at the end of the subtitle filename.
|
| 197 |
progress: gr.Progress
|
| 198 |
Indicator to show progress directly in gradio.
|
| 199 |
-
*
|
| 200 |
Parameters for the transcription pipeline. This will be dealt with "TranscriptionPipelineParams" data class
|
| 201 |
|
| 202 |
Returns
|
|
@@ -207,6 +207,11 @@ class BaseTranscriptionPipeline(ABC):
|
|
| 207 |
Output file path to return to gr.Files()
|
| 208 |
"""
|
| 209 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
if input_folder_path:
|
| 211 |
files = get_media_files(input_folder_path)
|
| 212 |
if isinstance(files, str):
|
|
@@ -220,7 +225,7 @@ class BaseTranscriptionPipeline(ABC):
|
|
| 220 |
file,
|
| 221 |
progress,
|
| 222 |
add_timestamp,
|
| 223 |
-
*
|
| 224 |
)
|
| 225 |
|
| 226 |
file_name, file_ext = os.path.splitext(os.path.basename(file))
|
|
@@ -229,7 +234,8 @@ class BaseTranscriptionPipeline(ABC):
|
|
| 229 |
output_file_name=file_name,
|
| 230 |
output_format=file_format,
|
| 231 |
result=transcribed_segments,
|
| 232 |
-
add_timestamp=add_timestamp
|
|
|
|
| 233 |
)
|
| 234 |
files_info[file_name] = {"subtitle": read_file(file_path), "time_for_task": time_for_task, "path": file_path}
|
| 235 |
|
|
@@ -256,7 +262,7 @@ class BaseTranscriptionPipeline(ABC):
|
|
| 256 |
file_format: str = "SRT",
|
| 257 |
add_timestamp: bool = True,
|
| 258 |
progress=gr.Progress(),
|
| 259 |
-
*
|
| 260 |
) -> list:
|
| 261 |
"""
|
| 262 |
Write subtitle file from microphone
|
|
@@ -271,7 +277,7 @@ class BaseTranscriptionPipeline(ABC):
|
|
| 271 |
Boolean value from gr.Checkbox() that determines whether to add a timestamp at the end of the filename.
|
| 272 |
progress: gr.Progress
|
| 273 |
Indicator to show progress directly in gradio.
|
| 274 |
-
*
|
| 275 |
Parameters related with whisper. This will be dealt with "WhisperParameters" data class
|
| 276 |
|
| 277 |
Returns
|
|
@@ -282,12 +288,17 @@ class BaseTranscriptionPipeline(ABC):
|
|
| 282 |
Output file path to return to gr.Files()
|
| 283 |
"""
|
| 284 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
progress(0, desc="Loading Audio..")
|
| 286 |
transcribed_segments, time_for_task = self.run(
|
| 287 |
mic_audio,
|
| 288 |
progress,
|
| 289 |
add_timestamp,
|
| 290 |
-
*
|
| 291 |
)
|
| 292 |
progress(1, desc="Completed!")
|
| 293 |
|
|
@@ -297,7 +308,8 @@ class BaseTranscriptionPipeline(ABC):
|
|
| 297 |
output_file_name=file_name,
|
| 298 |
output_format=file_format,
|
| 299 |
result=transcribed_segments,
|
| 300 |
-
add_timestamp=add_timestamp
|
|
|
|
| 301 |
)
|
| 302 |
|
| 303 |
result_str = f"Done in {self.format_time(time_for_task)}! Subtitle file is in the outputs folder.\n\n{subtitle}"
|
|
@@ -312,7 +324,7 @@ class BaseTranscriptionPipeline(ABC):
|
|
| 312 |
file_format: str = "SRT",
|
| 313 |
add_timestamp: bool = True,
|
| 314 |
progress=gr.Progress(),
|
| 315 |
-
*
|
| 316 |
) -> list:
|
| 317 |
"""
|
| 318 |
Write subtitle file from Youtube
|
|
@@ -327,7 +339,7 @@ class BaseTranscriptionPipeline(ABC):
|
|
| 327 |
Boolean value from gr.Checkbox() that determines whether to add a timestamp at the end of the filename.
|
| 328 |
progress: gr.Progress
|
| 329 |
Indicator to show progress directly in gradio.
|
| 330 |
-
*
|
| 331 |
Parameters related with whisper. This will be dealt with "WhisperParameters" data class
|
| 332 |
|
| 333 |
Returns
|
|
@@ -338,6 +350,11 @@ class BaseTranscriptionPipeline(ABC):
|
|
| 338 |
Output file path to return to gr.Files()
|
| 339 |
"""
|
| 340 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 341 |
progress(0, desc="Loading Audio from Youtube..")
|
| 342 |
yt = get_ytdata(youtube_link)
|
| 343 |
audio = get_ytaudio(yt)
|
|
@@ -346,7 +363,7 @@ class BaseTranscriptionPipeline(ABC):
|
|
| 346 |
audio,
|
| 347 |
progress,
|
| 348 |
add_timestamp,
|
| 349 |
-
*
|
| 350 |
)
|
| 351 |
|
| 352 |
progress(1, desc="Completed!")
|
|
@@ -357,7 +374,8 @@ class BaseTranscriptionPipeline(ABC):
|
|
| 357 |
output_file_name=file_name,
|
| 358 |
output_format=file_format,
|
| 359 |
result=transcribed_segments,
|
| 360 |
-
add_timestamp=add_timestamp
|
|
|
|
| 361 |
)
|
| 362 |
|
| 363 |
result_str = f"Done in {self.format_time(time_for_task)}! Subtitle file is in the outputs folder.\n\n{subtitle}"
|
|
|
|
| 178 |
file_format: str = "SRT",
|
| 179 |
add_timestamp: bool = True,
|
| 180 |
progress=gr.Progress(),
|
| 181 |
+
*pipeline_params,
|
| 182 |
) -> list:
|
| 183 |
"""
|
| 184 |
Write subtitle file from Files
|
|
|
|
| 196 |
Boolean value from gr.Checkbox() that determines whether to add a timestamp at the end of the subtitle filename.
|
| 197 |
progress: gr.Progress
|
| 198 |
Indicator to show progress directly in gradio.
|
| 199 |
+
*pipeline_params: tuple
|
| 200 |
Parameters for the transcription pipeline. This will be dealt with "TranscriptionPipelineParams" data class
|
| 201 |
|
| 202 |
Returns
|
|
|
|
| 207 |
Output file path to return to gr.Files()
|
| 208 |
"""
|
| 209 |
try:
|
| 210 |
+
params = TranscriptionPipelineParams.from_list(list(pipeline_params))
|
| 211 |
+
writer_options = {
|
| 212 |
+
"highlight_words": True if params.whisper.word_timestamps else False
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
if input_folder_path:
|
| 216 |
files = get_media_files(input_folder_path)
|
| 217 |
if isinstance(files, str):
|
|
|
|
| 225 |
file,
|
| 226 |
progress,
|
| 227 |
add_timestamp,
|
| 228 |
+
*pipeline_params,
|
| 229 |
)
|
| 230 |
|
| 231 |
file_name, file_ext = os.path.splitext(os.path.basename(file))
|
|
|
|
| 234 |
output_file_name=file_name,
|
| 235 |
output_format=file_format,
|
| 236 |
result=transcribed_segments,
|
| 237 |
+
add_timestamp=add_timestamp,
|
| 238 |
+
**writer_options
|
| 239 |
)
|
| 240 |
files_info[file_name] = {"subtitle": read_file(file_path), "time_for_task": time_for_task, "path": file_path}
|
| 241 |
|
|
|
|
| 262 |
file_format: str = "SRT",
|
| 263 |
add_timestamp: bool = True,
|
| 264 |
progress=gr.Progress(),
|
| 265 |
+
*pipeline_params,
|
| 266 |
) -> list:
|
| 267 |
"""
|
| 268 |
Write subtitle file from microphone
|
|
|
|
| 277 |
Boolean value from gr.Checkbox() that determines whether to add a timestamp at the end of the filename.
|
| 278 |
progress: gr.Progress
|
| 279 |
Indicator to show progress directly in gradio.
|
| 280 |
+
*pipeline_params: tuple
|
| 281 |
Parameters related with whisper. This will be dealt with "WhisperParameters" data class
|
| 282 |
|
| 283 |
Returns
|
|
|
|
| 288 |
Output file path to return to gr.Files()
|
| 289 |
"""
|
| 290 |
try:
|
| 291 |
+
params = TranscriptionPipelineParams.from_list(list(pipeline_params))
|
| 292 |
+
writer_options = {
|
| 293 |
+
"highlight_words": True if params.whisper.word_timestamps else False
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
progress(0, desc="Loading Audio..")
|
| 297 |
transcribed_segments, time_for_task = self.run(
|
| 298 |
mic_audio,
|
| 299 |
progress,
|
| 300 |
add_timestamp,
|
| 301 |
+
*pipeline_params,
|
| 302 |
)
|
| 303 |
progress(1, desc="Completed!")
|
| 304 |
|
|
|
|
| 308 |
output_file_name=file_name,
|
| 309 |
output_format=file_format,
|
| 310 |
result=transcribed_segments,
|
| 311 |
+
add_timestamp=add_timestamp,
|
| 312 |
+
**writer_options
|
| 313 |
)
|
| 314 |
|
| 315 |
result_str = f"Done in {self.format_time(time_for_task)}! Subtitle file is in the outputs folder.\n\n{subtitle}"
|
|
|
|
| 324 |
file_format: str = "SRT",
|
| 325 |
add_timestamp: bool = True,
|
| 326 |
progress=gr.Progress(),
|
| 327 |
+
*pipeline_params,
|
| 328 |
) -> list:
|
| 329 |
"""
|
| 330 |
Write subtitle file from Youtube
|
|
|
|
| 339 |
Boolean value from gr.Checkbox() that determines whether to add a timestamp at the end of the filename.
|
| 340 |
progress: gr.Progress
|
| 341 |
Indicator to show progress directly in gradio.
|
| 342 |
+
*pipeline_params: tuple
|
| 343 |
Parameters related with whisper. This will be dealt with "WhisperParameters" data class
|
| 344 |
|
| 345 |
Returns
|
|
|
|
| 350 |
Output file path to return to gr.Files()
|
| 351 |
"""
|
| 352 |
try:
|
| 353 |
+
params = TranscriptionPipelineParams.from_list(list(pipeline_params))
|
| 354 |
+
writer_options = {
|
| 355 |
+
"highlight_words": True if params.whisper.word_timestamps else False
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
progress(0, desc="Loading Audio from Youtube..")
|
| 359 |
yt = get_ytdata(youtube_link)
|
| 360 |
audio = get_ytaudio(yt)
|
|
|
|
| 363 |
audio,
|
| 364 |
progress,
|
| 365 |
add_timestamp,
|
| 366 |
+
*pipeline_params,
|
| 367 |
)
|
| 368 |
|
| 369 |
progress(1, desc="Completed!")
|
|
|
|
| 374 |
output_file_name=file_name,
|
| 375 |
output_format=file_format,
|
| 376 |
result=transcribed_segments,
|
| 377 |
+
add_timestamp=add_timestamp,
|
| 378 |
+
**writer_options
|
| 379 |
)
|
| 380 |
|
| 381 |
result_str = f"Done in {self.format_time(time_for_task)}! Subtitle file is in the outputs folder.\n\n{subtitle}"
|