Skip to content

Commit d0ed4fe

Browse files
authored
fix formatting in whisper notebook (#2281)
1 parent ff152a3 commit d0ed4fe

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

notebooks/whisper-subtitles-generation/whisper-subtitles-generation.ipynb

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,7 @@
461461
"source": [
462462
"inputs, duration = get_audio(output_file)\n",
463463
"\n",
464-
"transcription = pipe(\n",
465-
" inputs, generate_kwargs={\"task\": task.value}, return_timestamps=True\n",
466-
")[\"chunks\"]"
464+
"transcription = pipe(inputs, generate_kwargs={\"task\": task.value}, return_timestamps=True)[\"chunks\"]"
467465
]
468466
},
469467
{
@@ -491,9 +489,7 @@
491489
" seconds = milliseconds // 1_000\n",
492490
" milliseconds -= seconds * 1_000\n",
493491
"\n",
494-
" return (\n",
495-
" f\"{hours}:\" if hours > 0 else \"00:\"\n",
496-
" ) + f\"{minutes:02d}:{seconds:02d},{milliseconds:03d}\"\n",
492+
" return (f\"{hours}:\" if hours > 0 else \"00:\") + f\"{minutes:02d}:{seconds:02d},{milliseconds:03d}\"\n",
497493
"\n",
498494
"\n",
499495
"def prepare_srt(transcription, filter_duration=None):\n",
@@ -506,10 +502,7 @@
506502
" if segment[\"timestamp\"][1] is None:\n",
507503
" segment[\"timestamp\"] = (segment[\"timestamp\"][0], filter_duration)\n",
508504
"\n",
509-
" if filter_duration is not None and (\n",
510-
" segment[\"timestamp\"][0] >= math.floor(filter_duration)\n",
511-
" or segment[\"timestamp\"][1] > math.ceil(filter_duration) + 1\n",
512-
" ):\n",
505+
" if filter_duration is not None and (segment[\"timestamp\"][0] >= math.floor(filter_duration) or segment[\"timestamp\"][1] > math.ceil(filter_duration) + 1):\n",
513506
" break\n",
514507
" segment_lines.append(str(idx + 1) + \"\\n\")\n",
515508
" time_start = format_timestamp(segment[\"timestamp\"][0])\n",
@@ -1257,9 +1250,7 @@
12571250
" feature_extractor=processor.feature_extractor,\n",
12581251
" )\n",
12591252
" inputs, duration = get_audio(output_file)\n",
1260-
" transcription = int8_pipe(\n",
1261-
" inputs, generate_kwargs={\"task\": task.value}, return_timestamps=True\n",
1262-
" )[\"chunks\"]\n",
1253+
" transcription = int8_pipe(inputs, generate_kwargs={\"task\": task.value}, return_timestamps=True)[\"chunks\"]\n",
12631254
" srt_lines = prepare_srt(transcription, filter_duration=duration)\n",
12641255
" print(\"\".join(srt_lines))\n",
12651256
" widgets.Video.from_file(output_file, loop=False, width=800, height=800)"
@@ -1429,9 +1420,7 @@
14291420
" ydl.download(link.value)\n",
14301421
" inputs, duration = get_audio(output_file)\n",
14311422
" m_pipe = int8_pipe if use_int8 else pipe\n",
1432-
" transcription = m_pipe(\n",
1433-
" inputs, generate_kwargs={\"task\": task.lower()}, return_timestamps=True\n",
1434-
" )[\"chunks\"]\n",
1423+
" transcription = m_pipe(inputs, generate_kwargs={\"task\": task.lower()}, return_timestamps=True)[\"chunks\"]\n",
14351424
" srt_lines = prepare_srt(transcription, duration)\n",
14361425
" with output_file.with_suffix(\".srt\").open(\"w\") as f:\n",
14371426
" f.writelines(srt_lines)\n",

0 commit comments

Comments
 (0)