Update app.py
Browse files
app.py
CHANGED
|
@@ -462,7 +462,7 @@ async def process_text_with_progress(
|
|
| 462 |
):
|
| 463 |
# Input validation
|
| 464 |
if not text or text.strip() == "":
|
| 465 |
-
return None, None, None,
|
| 466 |
|
| 467 |
# Format pitch and rate strings
|
| 468 |
pitch_str = f"{pitch:+d}Hz" if pitch != 0 else "+0Hz"
|
|
@@ -485,19 +485,29 @@ async def process_text_with_progress(
|
|
| 485 |
progress_callback=update_progress,
|
| 486 |
parallel=parallel_processing
|
| 487 |
)
|
| 488 |
-
|
|
|
|
| 489 |
srt_download_link = create_download_link(srt_path, "Download Subtitles (.srt)")
|
| 490 |
audio_download_link = create_download_link(audio_path, "Download Audio (.mp3)")
|
| 491 |
|
| 492 |
-
#
|
| 493 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 494 |
|
| 495 |
except TTSError as e:
|
| 496 |
-
# Return
|
| 497 |
-
return None, None, None,
|
| 498 |
except Exception as e:
|
| 499 |
-
# Return
|
| 500 |
-
return None, None, None,
|
| 501 |
|
| 502 |
# Voice options dictionary
|
| 503 |
voice_options = {
|
|
@@ -614,25 +624,20 @@ with gr.Blocks(title="Advanced TTS with Configurable SRT Generation", analytics_
|
|
| 614 |
)
|
| 615 |
|
| 616 |
submit_btn = gr.Button("Generate Audio & Subtitles", elem_id="submit_btn")
|
| 617 |
-
|
| 618 |
-
# Add error message component
|
| 619 |
-
error_output = gr.Textbox(label="Status", visible=False, elem_id="error_output")
|
| 620 |
-
|
| 621 |
-
# Output components # Output components in a nicely organized column
|
| 622 |
with gr.Column(variant="panel") as output_col:
|
| 623 |
gr.Markdown("### Generated Output")
|
| 624 |
-
|
| 625 |
-
|
|
|
|
|
|
|
| 626 |
with gr.Row():
|
| 627 |
with gr.Column(scale=1):
|
| 628 |
-
srt_download = gr.HTML(label="", elem_id="srt_download"
|
| 629 |
with gr.Column(scale=1):
|
| 630 |
-
audio_download = gr.HTML(label="", elem_id="audio_download"
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
with gr.Column(visible=False):
|
| 634 |
-
srt_file = gr.File(elem_id="srt_file")
|
| 635 |
-
audio_file = gr.File(elem_id="audio_file")
|
| 636 |
|
| 637 |
# Handle button click
|
| 638 |
submit_btn.click(
|
|
@@ -647,13 +652,10 @@ with gr.Blocks(title="Advanced TTS with Configurable SRT Generation", analytics_
|
|
| 647 |
parallel_processing
|
| 648 |
],
|
| 649 |
outputs=[
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
audio_download,
|
| 655 |
-
error_output,
|
| 656 |
-
error_output
|
| 657 |
]
|
| 658 |
)
|
| 659 |
|
|
|
|
| 462 |
):
|
| 463 |
# Input validation
|
| 464 |
if not text or text.strip() == "":
|
| 465 |
+
return None, None, None, "Please enter some text to convert to speech."
|
| 466 |
|
| 467 |
# Format pitch and rate strings
|
| 468 |
pitch_str = f"{pitch:+d}Hz" if pitch != 0 else "+0Hz"
|
|
|
|
| 485 |
progress_callback=update_progress,
|
| 486 |
parallel=parallel_processing
|
| 487 |
)
|
| 488 |
+
|
| 489 |
+
# Create download links with descriptive labels
|
| 490 |
srt_download_link = create_download_link(srt_path, "Download Subtitles (.srt)")
|
| 491 |
audio_download_link = create_download_link(audio_path, "Download Audio (.mp3)")
|
| 492 |
|
| 493 |
+
# Return exactly 4 values in the expected order:
|
| 494 |
+
# 1. Audio preview path
|
| 495 |
+
# 2. SRT download button HTML
|
| 496 |
+
# 3. Audio download button HTML
|
| 497 |
+
# 4. Status message
|
| 498 |
+
return (
|
| 499 |
+
audio_path, # Audio preview
|
| 500 |
+
srt_download_link, # SRT download button
|
| 501 |
+
audio_download_link, # Audio download button
|
| 502 |
+
"Generation completed successfully!" # Status message
|
| 503 |
+
)
|
| 504 |
|
| 505 |
except TTSError as e:
|
| 506 |
+
# Return error state with proper number of outputs
|
| 507 |
+
return None, None, None, f"TTS Error: {str(e)}"
|
| 508 |
except Exception as e:
|
| 509 |
+
# Return error state with proper number of outputs
|
| 510 |
+
return None, None, None, f"Unexpected error: {str(e)}"
|
| 511 |
|
| 512 |
# Voice options dictionary
|
| 513 |
voice_options = {
|
|
|
|
| 624 |
)
|
| 625 |
|
| 626 |
submit_btn = gr.Button("Generate Audio & Subtitles", elem_id="submit_btn")
|
| 627 |
+
# Output components
|
|
|
|
|
|
|
|
|
|
|
|
|
| 628 |
with gr.Column(variant="panel") as output_col:
|
| 629 |
gr.Markdown("### Generated Output")
|
| 630 |
+
# Main output containers
|
| 631 |
+
with gr.Row():
|
| 632 |
+
audio_preview = gr.Audio(label="Preview Audio", elem_id="audio_preview")
|
| 633 |
+
|
| 634 |
with gr.Row():
|
| 635 |
with gr.Column(scale=1):
|
| 636 |
+
srt_download = gr.HTML(label="", elem_id="srt_download")
|
| 637 |
with gr.Column(scale=1):
|
| 638 |
+
audio_download = gr.HTML(label="", elem_id="audio_download")
|
| 639 |
+
|
| 640 |
+
error_output = gr.Textbox(label="Status", elem_id="error_output")
|
|
|
|
|
|
|
|
|
|
| 641 |
|
| 642 |
# Handle button click
|
| 643 |
submit_btn.click(
|
|
|
|
| 652 |
parallel_processing
|
| 653 |
],
|
| 654 |
outputs=[
|
| 655 |
+
audio_preview, # Audio preview
|
| 656 |
+
srt_download, # SRT download link
|
| 657 |
+
audio_download, # Audio download link
|
| 658 |
+
error_output # Status/error message
|
|
|
|
|
|
|
|
|
|
| 659 |
]
|
| 660 |
)
|
| 661 |
|