hivecorp commited on
Commit
104d704
·
verified ·
1 Parent(s): 33031ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -465,8 +465,8 @@ async def process_text_with_progress(
465
  ):
466
  # Input validation
467
  if not text or text.strip() == "":
468
- # Return None for file/audio outputs, and a string for error_output and download_link
469
- return None, None, None, "Please enter some text to convert to speech.", ""
470
 
471
  # Format pitch and rate strings
472
  pitch_str = f"{pitch:+d}Hz" if pitch != 0 else "+0Hz"
@@ -490,14 +490,14 @@ async def process_text_with_progress(
490
  parallel=parallel_processing
491
  )
492
 
493
- # If successful, return results and an empty string for error_output
494
- return srt_path, audio_path, audio_path, "", create_download_link(audio_path)
495
  except TTSError as e:
496
- # Return None for file/audio outputs, and specific TTS error message as string for error_output and download_link
497
- return None, None, None, f"TTS Error: {str(e)}", ""
498
  except Exception as e:
499
- # Return None for file/audio outputs, and any other error message as string for error_output and download_link
500
- return None, None, None, f"Unexpected error: {str(e)}", ""
501
 
502
  # Voice options dictionary
503
  voice_options = {
@@ -605,8 +605,8 @@ with gr.Blocks(title="Advanced TTS with Configurable SRT Generation") as app:
605
  submit_btn = gr.Button("Generate Audio & Subtitles")
606
 
607
  # Add error message component
608
- # Changed to always visible, and will display messages or be empty
609
- error_output = gr.Textbox(label="Status", interactive=False)
610
 
611
  with gr.Row():
612
  with gr.Column():
@@ -616,7 +616,8 @@ with gr.Blocks(title="Advanced TTS with Configurable SRT Generation") as app:
616
  # The download_link HTML component will contain an <a> tag with target="_blank"
617
  # This ensures that when the generated audio/SRT is downloaded via this link,
618
  # it will open in a new browser tab.
619
- download_link = gr.HTML(elem_classes="download-btn")
 
620
  # The audio_file component is typically for direct download via Gradio's file handling,
621
  # which might not open a new tab depending on browser settings.
622
  # The HTML download_link provides more control over opening in a new tab.
 
465
  ):
466
  # Input validation
467
  if not text or text.strip() == "":
468
+ # Return None for file/audio outputs, and use gr.update for error_output and download_link
469
+ return None, None, None, gr.update(value="Please enter some text to convert to speech.", visible=True), gr.update(value="", visible=False)
470
 
471
  # Format pitch and rate strings
472
  pitch_str = f"{pitch:+d}Hz" if pitch != 0 else "+0Hz"
 
490
  parallel=parallel_processing
491
  )
492
 
493
+ # If successful, return results and hide error_output, show download_link
494
+ return srt_path, audio_path, audio_path, gr.update(value="", visible=False), gr.update(value=create_download_link(audio_path), visible=True)
495
  except TTSError as e:
496
+ # Return None for file/audio outputs, show error_output, hide download_link
497
+ return None, None, None, gr.update(value=f"TTS Error: {str(e)}", visible=True), gr.update(value="", visible=False)
498
  except Exception as e:
499
+ # Return None for file/audio outputs, show error_output, hide download_link
500
+ return None, None, None, gr.update(value=f"Unexpected error: {str(e)}", visible=True), gr.update(value="", visible=False)
501
 
502
  # Voice options dictionary
503
  voice_options = {
 
605
  submit_btn = gr.Button("Generate Audio & Subtitles")
606
 
607
  # Add error message component
608
+ # Initialize error_output as hidden, and it will be shown/hidden via gr.update
609
+ error_output = gr.Textbox(label="Status", interactive=False, visible=False)
610
 
611
  with gr.Row():
612
  with gr.Column():
 
616
  # The download_link HTML component will contain an <a> tag with target="_blank"
617
  # This ensures that when the generated audio/SRT is downloaded via this link,
618
  # it will open in a new browser tab.
619
+ # Initialize download_link as hidden, and it will be shown/hidden via gr.update
620
+ download_link = gr.HTML(elem_classes="download-btn", visible=False)
621
  # The audio_file component is typically for direct download via Gradio's file handling,
622
  # which might not open a new tab depending on browser settings.
623
  # The HTML download_link provides more control over opening in a new tab.