Spaces:
Sleeping
Sleeping
Improve speed on CPU only
Browse files
app.py
CHANGED
@@ -48,12 +48,14 @@ if torch.cuda.is_available():
|
|
48 |
torch_dtype = torch.float16
|
49 |
speech_model_id = "openai/whisper-large-v3-turbo"
|
50 |
batch_size = 16
|
|
|
51 |
else:
|
52 |
model_device = "cpu"
|
53 |
pipeline_device = -1 # CPU for pipeline.
|
54 |
torch_dtype = torch.float32
|
55 |
speech_model_id = "openai/whisper-tiny"
|
56 |
batch_size = 2
|
|
|
57 |
|
58 |
try:
|
59 |
model = AutoModelForSpeechSeq2Seq.from_pretrained(
|
@@ -85,7 +87,7 @@ def transcribe_audio(audio_path: str, batch_size: int) -> Dict[str, Any]:
|
|
85 |
result = pipe(
|
86 |
audio_path,
|
87 |
chunk_length_s=10,
|
88 |
-
stride_length_s=
|
89 |
batch_size=batch_size,
|
90 |
return_timestamps=True,
|
91 |
)
|
@@ -198,8 +200,12 @@ def process_video(video_url: str):
|
|
198 |
srt_text = convert_to_srt(transcribed_text)
|
199 |
|
200 |
# Generate chapters from the SRT.
|
201 |
-
|
202 |
-
|
|
|
|
|
|
|
|
|
203 |
return srt_text, chapters
|
204 |
|
205 |
# -------------------------------------------
|
|
|
48 |
torch_dtype = torch.float16
|
49 |
speech_model_id = "openai/whisper-large-v3-turbo"
|
50 |
batch_size = 16
|
51 |
+
stride_length_s_tuple = (4, 2)
|
52 |
else:
|
53 |
model_device = "cpu"
|
54 |
pipeline_device = -1 # CPU for pipeline.
|
55 |
torch_dtype = torch.float32
|
56 |
speech_model_id = "openai/whisper-tiny"
|
57 |
batch_size = 2
|
58 |
+
stride_length_s_tuple = None
|
59 |
|
60 |
try:
|
61 |
model = AutoModelForSpeechSeq2Seq.from_pretrained(
|
|
|
87 |
result = pipe(
|
88 |
audio_path,
|
89 |
chunk_length_s=10,
|
90 |
+
stride_length_s=stride_length_s_tuple,
|
91 |
batch_size=batch_size,
|
92 |
return_timestamps=True,
|
93 |
)
|
|
|
200 |
srt_text = convert_to_srt(transcribed_text)
|
201 |
|
202 |
# Generate chapters from the SRT.
|
203 |
+
response = generate_chapters(srt_text)
|
204 |
+
|
205 |
+
# Extract only the chapters part and add a footer
|
206 |
+
cleaned_text = response.split("Chapters:")[1] if "Chapters:" in response else response
|
207 |
+
chapters = f"{cleaned_text.strip()}\n\nGenerated using free 'GenAI ChapterCraft' tool."
|
208 |
+
|
209 |
return srt_text, chapters
|
210 |
|
211 |
# -------------------------------------------
|