hivecorp commited on
Commit
2926dca
·
verified ·
1 Parent(s): fa07cc9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -12
app.py CHANGED
@@ -430,12 +430,12 @@ async def process_text_with_progress(
430
  ):
431
  # Input validation
432
  if not text or text.strip() == "":
433
- # For error case, return empty strings for markdown links and None for audio,
434
- # along with visibility updates for error_output
435
  return (
436
- None, # audio_output
437
- gr.update(value="", visible=False), # srt_download_link
438
- gr.update(value="", visible=False), # audio_download_link
439
  gr.update(value="Please enter some text to convert to speech.", visible=True) # error_output
440
  )
441
 
@@ -462,6 +462,8 @@ async def process_text_with_progress(
462
  )
463
 
464
  # Generate Markdown links for download that open in a new tab
 
 
465
  srt_download_link_html = f'<a href="file={srt_path}" download="subtitles.srt" target="_blank">Download SRT</a>'
466
  audio_download_link_html = f'<a href="file={audio_path}" download="audio.mp3" target="_blank">Download Audio</a>'
467
 
@@ -596,8 +598,8 @@ with gr.Blocks(title="Advanced TTS with Configurable SRT Generation") as app:
596
 
597
  # Add error message component - it should be visible initially
598
  # or its visibility handled in the return of the function
599
- error_output = gr.Textbox(label="Status", visible=True) # Changed to visible=True for easier debugging.
600
- # You can set it to False if you want it hidden by default.
601
 
602
  with gr.Row():
603
  with gr.Column():
@@ -605,8 +607,18 @@ with gr.Blocks(title="Advanced TTS with Configurable SRT Generation") as app:
605
  with gr.Column():
606
  # Change gr.File to gr.Markdown for download links
607
  # Set initial values to empty string and visible=False to hide them on load
608
- srt_download_link = gr.Markdown(value="", visible=False, label="Download SRT")
609
- audio_download_link = gr.Markdown(value="", visible=False, label="Download Audio")
 
 
 
 
 
 
 
 
 
 
610
 
611
  # Handle button click with manual error handling instead of .catch()
612
  submit_btn.click(
@@ -622,9 +634,9 @@ with gr.Blocks(title="Advanced TTS with Configurable SRT Generation") as app:
622
  ],
623
  outputs=[
624
  audio_output,
625
- srt_download_link,
626
- audio_download_link,
627
- error_output # Only one error_output here, as it's a single component
628
  ],
629
  api_name="generate"
630
  )
 
430
  ):
431
  # Input validation
432
  if not text or text.strip() == "":
433
+ # When an error occurs or input is invalid, return None for audio and empty strings
434
+ # for markdown, along with updates to error_output.
435
  return (
436
+ None, # audio_output
437
+ gr.update(value="", visible=False), # srt_download_link
438
+ gr.update(value="", visible=False), # audio_download_link
439
  gr.update(value="Please enter some text to convert to speech.", visible=True) # error_output
440
  )
441
 
 
462
  )
463
 
464
  # Generate Markdown links for download that open in a new tab
465
+ # For gr.Markdown, return the HTML string directly for the 'value'
466
+ # and use gr.update for visibility.
467
  srt_download_link_html = f'<a href="file={srt_path}" download="subtitles.srt" target="_blank">Download SRT</a>'
468
  audio_download_link_html = f'<a href="file={audio_path}" download="audio.mp3" target="_blank">Download Audio</a>'
469
 
 
598
 
599
  # Add error message component - it should be visible initially
600
  # or its visibility handled in the return of the function
601
+ # It's better to keep it hidden initially and show only on error
602
+ error_output = gr.Textbox(label="Status", visible=False)
603
 
604
  with gr.Row():
605
  with gr.Column():
 
607
  with gr.Column():
608
  # Change gr.File to gr.Markdown for download links
609
  # Set initial values to empty string and visible=False to hide them on load
610
+ # The label argument for gr.Markdown is deprecated in newer Gradio versions
611
+ # and might contribute to unexpected behavior or warnings.
612
+ # It's better to set the label directly in the value if needed, or use a separate gr.Textbox for label.
613
+ srt_download_link = gr.Markdown(value="", visible=False) # Removed label here
614
+ audio_download_link = gr.Markdown(value="", visible=False) # Removed label here
615
+
616
+ # Add a separate Textbox or Markdown for "Download SRT" and "Download Audio" labels
617
+ # if you need persistent labels for the download section.
618
+ gr.Markdown("**Download SRT:**")
619
+ srt_download_placeholder = gr.Markdown(value="", visible=False) # Placeholder for the actual link
620
+ gr.Markdown("**Download Audio:**")
621
+ audio_download_placeholder = gr.Markdown(value="", visible=False) # Placeholder for the actual link
622
 
623
  # Handle button click with manual error handling instead of .catch()
624
  submit_btn.click(
 
634
  ],
635
  outputs=[
636
  audio_output,
637
+ srt_download_placeholder, # Map to the new placeholder
638
+ audio_download_placeholder, # Map to the new placeholder
639
+ error_output
640
  ],
641
  api_name="generate"
642
  )