Spaces:
Paused
Paused
Update app_parallel.py
Browse files- app_parallel.py +5 -5
app_parallel.py
CHANGED
@@ -267,21 +267,21 @@ def split_audio(audio_path, chunk_duration=5):
|
|
267 |
with tempfile.NamedTemporaryFile(suffix=f"_chunk_{start_time}-{end_time}.wav", prefix="audio_chunk_", dir=TEMP_DIR.name, delete=False) as temp_file:
|
268 |
chunk_path = temp_file.name
|
269 |
chunk.write_audiofile(chunk_path)
|
270 |
-
audio_chunks.append(chunk_path)
|
271 |
|
272 |
return audio_chunks
|
273 |
|
274 |
# Generator function to yield chunk results as they are processed
|
275 |
def generate_chunks(audio_chunks, preprocessed_data, args):
|
276 |
-
future_to_chunk = {executor.submit(process_chunk, chunk, preprocessed_data, args): chunk for chunk in audio_chunks}
|
277 |
|
278 |
for future in as_completed(future_to_chunk):
|
279 |
-
|
280 |
try:
|
281 |
base64_video, temp_file_path = future.result() # Get the result of the completed task
|
282 |
-
yield json.dumps({'
|
283 |
except Exception as e:
|
284 |
-
yield f"Task for chunk {
|
285 |
|
286 |
@app.route("/run", methods=['POST'])
|
287 |
def parallel_processing():
|
|
|
267 |
with tempfile.NamedTemporaryFile(suffix=f"_chunk_{start_time}-{end_time}.wav", prefix="audio_chunk_", dir=TEMP_DIR.name, delete=False) as temp_file:
|
268 |
chunk_path = temp_file.name
|
269 |
chunk.write_audiofile(chunk_path)
|
270 |
+
audio_chunks.append((start_time, chunk_path))
|
271 |
|
272 |
return audio_chunks
|
273 |
|
274 |
# Generator function to yield chunk results as they are processed
|
275 |
def generate_chunks(audio_chunks, preprocessed_data, args):
|
276 |
+
future_to_chunk = {executor.submit(process_chunk, chunk[1], preprocessed_data, args): chunk[0] for chunk in audio_chunks}
|
277 |
|
278 |
for future in as_completed(future_to_chunk):
|
279 |
+
idx = future_to_chunk[future] # Get the original chunk that was processed
|
280 |
try:
|
281 |
base64_video, temp_file_path = future.result() # Get the result of the completed task
|
282 |
+
yield json.dumps({'start_time': idx, 'path': temp_file_path}).encode('utf-8')
|
283 |
except Exception as e:
|
284 |
+
yield f"Task for chunk {idx} failed: {e}\n"
|
285 |
|
286 |
@app.route("/run", methods=['POST'])
|
287 |
def parallel_processing():
|