Spanicin commited on
Commit
116013b
·
verified ·
1 Parent(s): d448a6d

Update app_parallel.py

Browse files
Files changed (1) hide show
  1. app_parallel.py +11 -14
app_parallel.py CHANGED
@@ -270,17 +270,17 @@ def generate_chunks(audio_chunks, preprocessed_data, args):
270
  global TEMP_DIR
271
  future_to_chunk = {executor.submit(process_chunk, chunk[1], preprocessed_data, args): chunk[0] for chunk in audio_chunks}
272
 
273
- # try:
274
- for future in as_completed(future_to_chunk):
275
- idx = future_to_chunk[future] # Get the original chunk that was processed
276
- try:
277
- base64_video, temp_file_path = future.result() # Get the result of the completed task
278
- yield json.dumps({'start_time': idx, 'base64_video': base64_video}).encode('utf-8')
279
- except Exception as e:
280
- yield f"Task for chunk {idx} failed: {e}\n"
281
- # finally:
282
- # if TEMP_DIR:
283
- # custom_cleanup(TEMP_DIR.name)
284
 
285
  @app.route("/run", methods=['POST'])
286
  def parallel_processing():
@@ -358,9 +358,6 @@ def parallel_processing():
358
  # base64_video, temp_file_path, duration = process_chunk(driven_audio_path, preprocessed_data, args)
359
  except Exception as e:
360
  return jsonify({'status': 'error', 'message': str(e)}), 500
361
- finally:
362
- if TEMP_DIR:
363
- custom_cleanup(TEMP_DIR.name)
364
 
365
  # @app.route("/stream", methods=["GET"])
366
  # def stream_results():
 
270
  global TEMP_DIR
271
  future_to_chunk = {executor.submit(process_chunk, chunk[1], preprocessed_data, args): chunk[0] for chunk in audio_chunks}
272
 
273
+ try:
274
+ for future in as_completed(future_to_chunk):
275
+ idx = future_to_chunk[future] # Get the original chunk that was processed
276
+ try:
277
+ base64_video, temp_file_path = future.result() # Get the result of the completed task
278
+ yield json.dumps({'start_time': idx, 'base64_video': base64_video}).encode('utf-8')
279
+ except Exception as e:
280
+ yield f"Task for chunk {idx} failed: {e}\n"
281
+ finally:
282
+ if TEMP_DIR:
283
+ custom_cleanup(TEMP_DIR.name)
284
 
285
  @app.route("/run", methods=['POST'])
286
  def parallel_processing():
 
358
  # base64_video, temp_file_path, duration = process_chunk(driven_audio_path, preprocessed_data, args)
359
  except Exception as e:
360
  return jsonify({'status': 'error', 'message': str(e)}), 500
 
 
 
361
 
362
  # @app.route("/stream", methods=["GET"])
363
  # def stream_results():