Spaces:
Paused
Paused
Update app_parallel.py
Browse files- app_parallel.py +6 -4
app_parallel.py
CHANGED
@@ -292,7 +292,7 @@ def split_audio(audio_path, TEMP_DIR, chunk_duration):
|
|
292 |
# return int(match.group(1)) if match else -1 # Return -1 if no match is found, handle appropriately.
|
293 |
# Generator function to yield chunk results as they are processed
|
294 |
|
295 |
-
def generate_chunks(audio_chunks, preprocessed_data, args, m3u8_path, audio_duration):
|
296 |
global TEMP_DIR
|
297 |
future_to_chunk = {executor.submit(process_chunk, chunk[1], preprocessed_data, args): chunk[0] for chunk in audio_chunks}
|
298 |
processed_chunks = {chunk[0]: None for chunk in audio_chunks}
|
@@ -310,7 +310,9 @@ def generate_chunks(audio_chunks, preprocessed_data, args, m3u8_path, audio_dura
|
|
310 |
asyncio.set_event_loop(loop)
|
311 |
loop.run_until_complete(add_video(processed_chunks[expected_start_time], m3u8_path, audio_duration))
|
312 |
loop.close()
|
313 |
-
|
|
|
|
|
314 |
processed_chunks[expected_start_time] = None
|
315 |
yielded_count += 1
|
316 |
else:
|
@@ -396,12 +398,12 @@ def parallel_processing():
|
|
396 |
|
397 |
@app.route("/stream", methods=["GET"])
|
398 |
def stream_results():
|
399 |
-
global audio_chunks, preprocessed_data, args, m3u8_path, audio_duration
|
400 |
print("audio_chunks",audio_chunks)
|
401 |
print("preprocessed_data",preprocessed_data)
|
402 |
print("args",args)
|
403 |
try:
|
404 |
-
return stream_with_context(generate_chunks(audio_chunks, preprocessed_data, args, m3u8_path, audio_duration))
|
405 |
except Exception as e:
|
406 |
return jsonify({'status': 'error', 'message': str(e)}), 500
|
407 |
|
|
|
292 |
# return int(match.group(1)) if match else -1 # Return -1 if no match is found, handle appropriately.
|
293 |
# Generator function to yield chunk results as they are processed
|
294 |
|
295 |
+
def generate_chunks(audio_chunks, preprocessed_data, args, m3u8_path, audio_duration, start_time):
|
296 |
global TEMP_DIR
|
297 |
future_to_chunk = {executor.submit(process_chunk, chunk[1], preprocessed_data, args): chunk[0] for chunk in audio_chunks}
|
298 |
processed_chunks = {chunk[0]: None for chunk in audio_chunks}
|
|
|
310 |
asyncio.set_event_loop(loop)
|
311 |
loop.run_until_complete(add_video(processed_chunks[expected_start_time], m3u8_path, audio_duration))
|
312 |
loop.close()
|
313 |
+
end_time = time.time()
|
314 |
+
elapsed_time = end_time - start_time
|
315 |
+
yield json.dumps({'start_time': expected_start_time, 'video_index': yielded_count, 'elapsed_time': elapsed_time}).encode('utf-8')
|
316 |
processed_chunks[expected_start_time] = None
|
317 |
yielded_count += 1
|
318 |
else:
|
|
|
398 |
|
399 |
@app.route("/stream", methods=["GET"])
|
400 |
def stream_results():
|
401 |
+
global audio_chunks, preprocessed_data, args, m3u8_path, audio_duration, start_time
|
402 |
print("audio_chunks",audio_chunks)
|
403 |
print("preprocessed_data",preprocessed_data)
|
404 |
print("args",args)
|
405 |
try:
|
406 |
+
return stream_with_context(generate_chunks(audio_chunks, preprocessed_data, args, m3u8_path, audio_duration, start_time))
|
407 |
except Exception as e:
|
408 |
return jsonify({'status': 'error', 'message': str(e)}), 500
|
409 |
|