Spaces:
Paused
Paused
Update app_parallel.py
Browse files- app_parallel.py +6 -5
app_parallel.py
CHANGED
@@ -80,6 +80,7 @@ preprocessed_data = None
|
|
80 |
args = None
|
81 |
unique_id = None
|
82 |
m3u8_path = None
|
|
|
83 |
|
84 |
app.config['temp_response'] = None
|
85 |
app.config['generation_thread'] = None
|
@@ -287,7 +288,7 @@ def split_audio(audio_path, TEMP_DIR, chunk_duration):
|
|
287 |
return audio_chunks, total_duration
|
288 |
|
289 |
# Generator function to yield chunk results as they are processed
|
290 |
-
def generate_chunks(audio_chunks, preprocessed_data, args, m3u8_path):
|
291 |
global TEMP_DIR
|
292 |
future_to_chunk = {executor.submit(process_chunk, chunk[1], preprocessed_data, args): chunk[0] for chunk in audio_chunks}
|
293 |
|
@@ -299,7 +300,7 @@ def generate_chunks(audio_chunks, preprocessed_data, args, m3u8_path):
|
|
299 |
# add video for streaming
|
300 |
loop = asyncio.new_event_loop()
|
301 |
asyncio.set_event_loop(loop)
|
302 |
-
loop.run_until_complete(add_video(temp_file_path, m3u8_path))
|
303 |
loop.close()
|
304 |
yield json.dumps({'start_time': idx, 'video_index': chunk_idx}).encode('utf-8')
|
305 |
except Exception as e:
|
@@ -311,7 +312,7 @@ def generate_chunks(audio_chunks, preprocessed_data, args, m3u8_path):
|
|
311 |
@app.route("/run", methods=['POST'])
|
312 |
def parallel_processing():
|
313 |
global start_time
|
314 |
-
global audio_chunks, preprocessed_data, args, m3u8_path
|
315 |
start_time = time.time()
|
316 |
global TEMP_DIR
|
317 |
TEMP_DIR = create_temp_dir()
|
@@ -382,12 +383,12 @@ def parallel_processing():
|
|
382 |
|
383 |
@app.route("/stream", methods=["GET"])
|
384 |
def stream_results():
|
385 |
-
global audio_chunks, preprocessed_data, args, m3u8_path
|
386 |
print("audio_chunks",audio_chunks)
|
387 |
print("preprocessed_data",preprocessed_data)
|
388 |
print("args",args)
|
389 |
try:
|
390 |
-
return stream_with_context(generate_chunks(audio_chunks, preprocessed_data, args, m3u8_path))
|
391 |
except Exception as e:
|
392 |
return jsonify({'status': 'error', 'message': str(e)}), 500
|
393 |
|
|
|
80 |
args = None
|
81 |
unique_id = None
|
82 |
m3u8_path = None
|
83 |
+
audio_duration = None
|
84 |
|
85 |
app.config['temp_response'] = None
|
86 |
app.config['generation_thread'] = None
|
|
|
288 |
return audio_chunks, total_duration
|
289 |
|
290 |
# Generator function to yield chunk results as they are processed
|
291 |
+
def generate_chunks(audio_chunks, preprocessed_data, args, m3u8_path, audio_duration):
|
292 |
global TEMP_DIR
|
293 |
future_to_chunk = {executor.submit(process_chunk, chunk[1], preprocessed_data, args): chunk[0] for chunk in audio_chunks}
|
294 |
|
|
|
300 |
# add video for streaming
|
301 |
loop = asyncio.new_event_loop()
|
302 |
asyncio.set_event_loop(loop)
|
303 |
+
loop.run_until_complete(add_video(temp_file_path, m3u8_path, audio_duration))
|
304 |
loop.close()
|
305 |
yield json.dumps({'start_time': idx, 'video_index': chunk_idx}).encode('utf-8')
|
306 |
except Exception as e:
|
|
|
312 |
@app.route("/run", methods=['POST'])
|
313 |
def parallel_processing():
|
314 |
global start_time
|
315 |
+
global audio_chunks, preprocessed_data, args, m3u8_path, audio_duration
|
316 |
start_time = time.time()
|
317 |
global TEMP_DIR
|
318 |
TEMP_DIR = create_temp_dir()
|
|
|
383 |
|
384 |
@app.route("/stream", methods=["GET"])
|
385 |
def stream_results():
|
386 |
+
global audio_chunks, preprocessed_data, args, m3u8_path, audio_duration
|
387 |
print("audio_chunks",audio_chunks)
|
388 |
print("preprocessed_data",preprocessed_data)
|
389 |
print("args",args)
|
390 |
try:
|
391 |
+
return stream_with_context(generate_chunks(audio_chunks, preprocessed_data, args, m3u8_path, audio_duration))
|
392 |
except Exception as e:
|
393 |
return jsonify({'status': 'error', 'message': str(e)}), 500
|
394 |
|