Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -412,7 +412,7 @@ async def generate_accurate_srt(
|
|
| 412 |
|
| 413 |
return srt_path, audio_path
|
| 414 |
|
| 415 |
-
# IMPROVEMENT 4: Progress Reporting
|
| 416 |
async def process_text_with_progress(
|
| 417 |
text,
|
| 418 |
pitch,
|
|
@@ -425,7 +425,7 @@ async def process_text_with_progress(
|
|
| 425 |
):
|
| 426 |
# Input validation
|
| 427 |
if not text or text.strip() == "":
|
| 428 |
-
|
| 429 |
|
| 430 |
# Format pitch and rate strings
|
| 431 |
pitch_str = f"{pitch:+d}Hz" if pitch != 0 else "+0Hz"
|
|
@@ -449,11 +449,14 @@ async def process_text_with_progress(
|
|
| 449 |
parallel=parallel_processing
|
| 450 |
)
|
| 451 |
|
| 452 |
-
|
|
|
|
| 453 |
except TTSError as e:
|
| 454 |
-
|
|
|
|
| 455 |
except Exception as e:
|
| 456 |
-
|
|
|
|
| 457 |
|
| 458 |
# Voice options dictionary
|
| 459 |
voice_options = {
|
|
@@ -560,6 +563,9 @@ with gr.Blocks(title="Advanced TTS with Configurable SRT Generation") as app:
|
|
| 560 |
|
| 561 |
submit_btn = gr.Button("Generate Audio & Subtitles")
|
| 562 |
|
|
|
|
|
|
|
|
|
|
| 563 |
with gr.Row():
|
| 564 |
with gr.Column():
|
| 565 |
audio_output = gr.Audio(label="Preview Audio")
|
|
@@ -567,10 +573,7 @@ with gr.Blocks(title="Advanced TTS with Configurable SRT Generation") as app:
|
|
| 567 |
srt_file = gr.File(label="Download SRT")
|
| 568 |
audio_file = gr.File(label="Download Audio")
|
| 569 |
|
| 570 |
-
#
|
| 571 |
-
error_output = gr.Textbox(label="Status", visible=False)
|
| 572 |
-
|
| 573 |
-
# Handle button click
|
| 574 |
submit_btn.click(
|
| 575 |
fn=process_text_with_progress,
|
| 576 |
inputs=[
|
|
@@ -585,12 +588,11 @@ with gr.Blocks(title="Advanced TTS with Configurable SRT Generation") as app:
|
|
| 585 |
outputs=[
|
| 586 |
srt_file,
|
| 587 |
audio_file,
|
| 588 |
-
audio_output
|
|
|
|
|
|
|
| 589 |
],
|
| 590 |
api_name="generate"
|
| 591 |
-
).catch(
|
| 592 |
-
fn=lambda e: {"visible": True, "value": str(e)},
|
| 593 |
-
outputs=[error_output]
|
| 594 |
)
|
| 595 |
|
| 596 |
if __name__ == "__main__":
|
|
|
|
| 412 |
|
| 413 |
return srt_path, audio_path
|
| 414 |
|
| 415 |
+
# IMPROVEMENT 4: Progress Reporting with proper error handling for older Gradio versions
|
| 416 |
async def process_text_with_progress(
|
| 417 |
text,
|
| 418 |
pitch,
|
|
|
|
| 425 |
):
|
| 426 |
# Input validation
|
| 427 |
if not text or text.strip() == "":
|
| 428 |
+
return None, None, None, True, "Please enter some text to convert to speech."
|
| 429 |
|
| 430 |
# Format pitch and rate strings
|
| 431 |
pitch_str = f"{pitch:+d}Hz" if pitch != 0 else "+0Hz"
|
|
|
|
| 449 |
parallel=parallel_processing
|
| 450 |
)
|
| 451 |
|
| 452 |
+
# If successful, return results and hide error
|
| 453 |
+
return srt_path, audio_path, audio_path, False, ""
|
| 454 |
except TTSError as e:
|
| 455 |
+
# Return specific TTS error
|
| 456 |
+
return None, None, None, True, f"TTS Error: {str(e)}"
|
| 457 |
except Exception as e:
|
| 458 |
+
# Return any other error
|
| 459 |
+
return None, None, None, True, f"Unexpected error: {str(e)}"
|
| 460 |
|
| 461 |
# Voice options dictionary
|
| 462 |
voice_options = {
|
|
|
|
| 563 |
|
| 564 |
submit_btn = gr.Button("Generate Audio & Subtitles")
|
| 565 |
|
| 566 |
+
# Add error message component
|
| 567 |
+
error_output = gr.Textbox(label="Status", visible=False)
|
| 568 |
+
|
| 569 |
with gr.Row():
|
| 570 |
with gr.Column():
|
| 571 |
audio_output = gr.Audio(label="Preview Audio")
|
|
|
|
| 573 |
srt_file = gr.File(label="Download SRT")
|
| 574 |
audio_file = gr.File(label="Download Audio")
|
| 575 |
|
| 576 |
+
# Handle button click with manual error handling instead of .catch()
|
|
|
|
|
|
|
|
|
|
| 577 |
submit_btn.click(
|
| 578 |
fn=process_text_with_progress,
|
| 579 |
inputs=[
|
|
|
|
| 588 |
outputs=[
|
| 589 |
srt_file,
|
| 590 |
audio_file,
|
| 591 |
+
audio_output,
|
| 592 |
+
error_output,
|
| 593 |
+
error_output
|
| 594 |
],
|
| 595 |
api_name="generate"
|
|
|
|
|
|
|
|
|
|
| 596 |
)
|
| 597 |
|
| 598 |
if __name__ == "__main__":
|