jdana commited on
Commit
16e76af
·
verified ·
1 Parent(s): 90e07d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -13
app.py CHANGED
@@ -234,11 +234,11 @@ def show_converted_audiobooks():
234
  if not os.path.exists(output_dir):
235
  return ["No audiobooks found."]
236
 
237
- files = [f for f in os.listdir(output_dir) if f.endswith(('.mp3', '.m4b'))]
238
  if not files:
239
  return ["No audiobooks found."]
240
 
241
- return [os.path.join(output_dir, f) for f in files]
242
 
243
  @gpu_decorator
244
  def infer(ref_audio_orig, ref_text, gen_text, cross_fade_duration=0.0, speed=1, show_info=gr.Info, progress=gr.Progress()):
@@ -274,8 +274,7 @@ def infer(ref_audio_orig, ref_text, gen_text, cross_fade_duration=0.0, speed=1,
274
  def basic_tts(ref_audio_input, ref_text_input, gen_file_input, cross_fade_duration, speed, progress=gr.Progress()):
275
  """Main function to convert eBooks to audiobooks."""
276
  try:
277
- last_file = None
278
-
279
  num_ebooks = len(gen_file_input)
280
  for idx, ebook in enumerate(gen_file_input):
281
  progress(0, desc=f"Processing ebook {idx+1}/{num_ebooks}")
@@ -337,12 +336,12 @@ def basic_tts(ref_audio_input, ref_text_input, gen_file_input, cross_fade_durati
337
  if cover_image and os.path.exists(cover_image):
338
  os.remove(cover_image)
339
 
340
- last_file = tmp_mp3_path
341
- progress(1, desc="Completed processing ebook")
342
-
343
- audiobooks = show_converted_audiobooks()
344
 
345
- return last_file, audiobooks
 
 
346
 
347
  except Exception as e:
348
  print(f"An error occurred: {e}")
@@ -365,11 +364,12 @@ def create_gradio_app():
365
  file_count="multiple",
366
  )
367
 
368
- generate_btn = gr.Button("Start", variant="primary")
369
-
370
- show_audiobooks_btn = gr.Button("Show All Completed Audiobooks", variant="secondary")
371
- audiobooks_output = gr.Files(label="Converted Audiobooks (Download Links ->)")
372
 
 
373
  player = gr.Audio(label="Play Latest Converted Audiobook", interactive=False)
374
 
375
  with gr.Accordion("Advanced Settings", open=False):
 
234
  if not os.path.exists(output_dir):
235
  return ["No audiobooks found."]
236
 
237
+ files = [os.path.join(output_dir, f) for f in os.listdir(output_dir) if f.endswith(('.mp3', '.m4b'))]
238
  if not files:
239
  return ["No audiobooks found."]
240
 
241
+ return files
242
 
243
  @gpu_decorator
244
  def infer(ref_audio_orig, ref_text, gen_text, cross_fade_duration=0.0, speed=1, show_info=gr.Info, progress=gr.Progress()):
 
274
  def basic_tts(ref_audio_input, ref_text_input, gen_file_input, cross_fade_duration, speed, progress=gr.Progress()):
275
  """Main function to convert eBooks to audiobooks."""
276
  try:
277
+ processed_audiobooks = []
 
278
  num_ebooks = len(gen_file_input)
279
  for idx, ebook in enumerate(gen_file_input):
280
  progress(0, desc=f"Processing ebook {idx+1}/{num_ebooks}")
 
336
  if cover_image and os.path.exists(cover_image):
337
  os.remove(cover_image)
338
 
339
+ processed_audiobooks.append(tmp_mp3_path)
340
+ progress(1, desc=f"Completed processing ebook {idx+1}/{num_ebooks}")
 
 
341
 
342
+ # Yield the outputs after processing each ebook
343
+ player_audio = tmp_mp3_path # Path to the latest audio file
344
+ yield player_audio, processed_audiobooks # Yield the updated outputs
345
 
346
  except Exception as e:
347
  print(f"An error occurred: {e}")
 
364
  file_count="multiple",
365
  )
366
 
367
+ # Arrange the two buttons side by side using gr.Row
368
+ with gr.Row():
369
+ generate_btn = gr.Button("Start", variant="primary")
370
+ show_audiobooks_btn = gr.Button("Show All Completed Audiobooks", variant="secondary")
371
 
372
+ audiobooks_output = gr.Files(label="Converted Audiobooks (Download Links)")
373
  player = gr.Audio(label="Play Latest Converted Audiobook", interactive=False)
374
 
375
  with gr.Accordion("Advanced Settings", open=False):