hivecorp commited on
Commit
d9e730a
·
verified ·
1 Parent(s): 3927c7f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
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 indicator
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 with progress tracking
63
- for result in progress.track(asyncio.as_completed(tasks), total=len(tasks), description="Processing batches..."):
64
- srt_content, audio_file, end_offset = await result
 
 
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: