Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -46,7 +46,7 @@ async def generate_accurate_srt(batch_text, batch_num, start_offset):
|
|
| 46 |
|
| 47 |
return srt_content, audio_file, start_time
|
| 48 |
|
| 49 |
-
# Batch processing function with concurrent processing and progress
|
| 50 |
async def batch_process_srt_and_audio(script_text, progress=gr.Progress()):
|
| 51 |
batches = [script_text[i:i+500] for i in range(0, len(script_text), 500)]
|
| 52 |
all_srt_content = ""
|
|
@@ -59,9 +59,11 @@ async def batch_process_srt_and_audio(script_text, progress=gr.Progress()):
|
|
| 59 |
for batch_num, batch_text in enumerate(batches)
|
| 60 |
]
|
| 61 |
|
| 62 |
-
# Execute tasks concurrently
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
| 65 |
all_srt_content += srt_content
|
| 66 |
|
| 67 |
# Append the audio of each batch to the combined audio
|
|
@@ -72,6 +74,10 @@ async def batch_process_srt_and_audio(script_text, progress=gr.Progress()):
|
|
| 72 |
# Clean up the individual batch audio file
|
| 73 |
os.remove(audio_file)
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
# Export combined audio and SRT
|
| 76 |
combined_audio.export("final_audio.wav", format="wav")
|
| 77 |
with open("final_subtitles.srt", "w") as srt_file:
|
|
|
|
| 46 |
|
| 47 |
return srt_content, audio_file, start_time
|
| 48 |
|
| 49 |
+
# Batch processing function with concurrent processing and manual progress update
|
| 50 |
async def batch_process_srt_and_audio(script_text, progress=gr.Progress()):
|
| 51 |
batches = [script_text[i:i+500] for i in range(0, len(script_text), 500)]
|
| 52 |
all_srt_content = ""
|
|
|
|
| 59 |
for batch_num, batch_text in enumerate(batches)
|
| 60 |
]
|
| 61 |
|
| 62 |
+
# Execute tasks concurrently and update progress after each completion
|
| 63 |
+
completed_tasks = 0
|
| 64 |
+
total_tasks = len(tasks)
|
| 65 |
+
for task in asyncio.as_completed(tasks):
|
| 66 |
+
srt_content, audio_file, end_offset = await task
|
| 67 |
all_srt_content += srt_content
|
| 68 |
|
| 69 |
# Append the audio of each batch to the combined audio
|
|
|
|
| 74 |
# Clean up the individual batch audio file
|
| 75 |
os.remove(audio_file)
|
| 76 |
|
| 77 |
+
# Update progress
|
| 78 |
+
completed_tasks += 1
|
| 79 |
+
progress(completed_tasks / total_tasks)
|
| 80 |
+
|
| 81 |
# Export combined audio and SRT
|
| 82 |
combined_audio.export("final_audio.wav", format="wav")
|
| 83 |
with open("final_subtitles.srt", "w") as srt_file:
|