cache info rates
Browse files
app.py
CHANGED
@@ -168,41 +168,50 @@ def strike(url, speedup_factor, min_speedup, max_speedup, max_num_segments):
|
|
168 |
|
169 |
with st.spinner("downloading..."):
|
170 |
name = download(url, YDL_OPTS)
|
171 |
-
|
172 |
-
|
173 |
|
174 |
-
|
175 |
-
|
176 |
-
|
|
|
177 |
|
178 |
with st.spinner("transcribing..."):
|
179 |
segments = transcribe(audio_path, transcript_path)
|
180 |
|
181 |
-
|
182 |
|
183 |
with st.spinner("calculating information density..."):
|
184 |
-
|
185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
)
|
187 |
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
max_speedup,
|
203 |
-
squashed_durations,
|
204 |
-
total_duration,
|
205 |
-
)
|
206 |
|
207 |
with st.spinner("stitching segments..."):
|
208 |
cat_clips(squashed_times, speedups, audio_path, output_path)
|
|
|
168 |
|
169 |
with st.spinner("downloading..."):
|
170 |
name = download(url, YDL_OPTS)
|
171 |
+
assert name.endswith(".m4a")
|
172 |
+
name = name.split(".m4a")[0].split("/")[-1]
|
173 |
|
174 |
+
audio_path = os.path.join(DATA_DIR, "%s.mp3" % name)
|
175 |
+
transcript_path = os.path.join(DATA_DIR, "%s.json" % name)
|
176 |
+
density_path = os.path.join(DATA_DIR, "%s.npy" % name)
|
177 |
+
output_path = os.path.join(DATA_DIR, "%s_smooth.mp3" % name)
|
178 |
|
179 |
with st.spinner("transcribing..."):
|
180 |
segments = transcribe(audio_path, transcript_path)
|
181 |
|
182 |
+
seg_durations = compute_seg_durations(segments)
|
183 |
|
184 |
with st.spinner("calculating information density..."):
|
185 |
+
if os.path.exists(density_path):
|
186 |
+
with open(density_path, "rb") as f:
|
187 |
+
info_densities = np.load(f)
|
188 |
+
else:
|
189 |
+
info_densities = compute_info_densities(
|
190 |
+
segments, seg_durations, llm, tokenizer, device
|
191 |
+
)
|
192 |
+
with open(density_path, "wb") as f:
|
193 |
+
np.save(f, info_densities)
|
194 |
+
|
195 |
+
total_duration = segments[-1]["end"] - segments[0]["start"]
|
196 |
+
min_sec_leaf = total_duration / max_num_segments
|
197 |
+
smoothed_info_densities = smooth_info_densities(
|
198 |
+
info_densities, seg_durations, max_num_segments, min_sec_leaf
|
199 |
)
|
200 |
|
201 |
+
squashed_times, squashed_densities = squash_segs(
|
202 |
+
segments, smoothed_info_densities
|
203 |
+
)
|
204 |
+
squashed_durations = np.array([end - start for start, end in squashed_times])
|
205 |
+
|
206 |
+
speedups = compute_speedups(squashed_densities)
|
207 |
+
speedups = postprocess_speedups(
|
208 |
+
speedups,
|
209 |
+
speedup_factor,
|
210 |
+
min_speedup,
|
211 |
+
max_speedup,
|
212 |
+
squashed_durations,
|
213 |
+
total_duration,
|
214 |
+
)
|
|
|
|
|
|
|
|
|
215 |
|
216 |
with st.spinner("stitching segments..."):
|
217 |
cat_clips(squashed_times, speedups, audio_path, output_path)
|