hivecorp commited on
Commit
1c3d9c2
Β·
verified Β·
1 Parent(s): a63a008

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +176 -78
app.py CHANGED
@@ -15,6 +15,7 @@ import multiprocessing
15
  import psutil
16
  import concurrent.futures
17
  import gc
 
18
 
19
  class TimingManager:
20
  def __init__(self):
@@ -523,92 +524,189 @@ voice_options = {
523
  import atexit
524
  atexit.register(file_manager.cleanup_all)
525
 
526
- # Create Gradio interface
527
- with gr.Blocks(title="Advanced TTS with Configurable SRT Generation") as app:
528
- gr.Markdown("# Advanced TTS with Configurable SRT Generation")
529
- gr.Markdown("Generate perfectly synchronized audio and subtitles with natural speech patterns.")
530
-
531
- with gr.Row():
532
- with gr.Column(scale=3):
533
- text_input = gr.Textbox(label="Enter Text", lines=10, placeholder="Enter your text here...")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
534
 
535
- with gr.Column(scale=2):
536
- voice_dropdown = gr.Dropdown(
537
- label="Select Voice",
538
- choices=list(voice_options.keys()),
539
- value="Jenny Female"
540
- )
541
- pitch_slider = gr.Slider(
542
- label="Pitch Adjustment (Hz)",
543
- minimum=-10,
544
- maximum=10,
545
- value=0,
546
- step=1
547
- )
548
- rate_slider = gr.Slider(
549
- label="Rate Adjustment (%)",
550
- minimum=-25,
551
- maximum=25,
552
- value=0,
553
- step=1
554
- )
555
-
556
- with gr.Row():
557
- with gr.Column():
558
- words_per_line = gr.Slider(
559
- label="Words per Line",
560
- minimum=3,
561
- maximum=12,
562
- value=6,
563
- step=1,
564
- info="Controls how many words appear on each line of the subtitle"
565
- )
566
- with gr.Column():
567
- lines_per_segment = gr.Slider(
568
- label="Lines per Segment",
569
- minimum=1,
570
- maximum=4,
571
- value=2,
572
- step=1,
573
- info="Controls how many lines appear in each subtitle segment"
574
- )
575
- with gr.Column():
576
- parallel_processing = gr.Checkbox(
577
- label="Enable Parallel Processing",
578
- value=True,
579
- info="Process multiple segments simultaneously for faster conversion (recommended for longer texts)"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
580
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
581
 
582
- submit_btn = gr.Button("Generate Audio & Subtitles")
583
-
584
- # Add error message component
585
- error_output = gr.Textbox(label="Status", visible=False)
586
-
587
- with gr.Row():
588
- with gr.Column():
589
- audio_output = gr.Audio(label="Preview Audio")
590
- with gr.Column():
591
- srt_file = gr.File(label="Download SRT")
592
- audio_file = gr.File(label="Download Audio")
593
-
594
- # Handle button click with manual error handling instead of .catch()
595
  submit_btn.click(
596
  fn=process_text_with_progress,
597
  inputs=[
598
- text_input,
599
- pitch_slider,
600
- rate_slider,
601
- voice_dropdown,
602
- words_per_line,
603
- lines_per_segment,
604
- parallel_processing
605
  ],
606
  outputs=[
607
- srt_file,
608
- audio_file,
609
- audio_output,
610
- error_output,
611
- error_output
612
  ],
613
  api_name="generate"
614
  )
 
15
  import psutil
16
  import concurrent.futures
17
  import gc
18
+ from gradio.themes import Monochrome
19
 
20
  class TimingManager:
21
  def __init__(self):
 
524
  import atexit
525
  atexit.register(file_manager.cleanup_all)
526
 
527
+ # Create custom theme
528
+ theme = Monochrome().set(
529
+ primary_hue="blue",
530
+ secondary_hue="slate",
531
+ neutral_hue="zinc",
532
+ )
533
+
534
+ # Create Gradio interface with modern UI
535
+ with gr.Blocks(
536
+ title="Text to Speech Studio",
537
+ theme=theme,
538
+ css="""
539
+ .container { max-width: 1200px; margin: auto; }
540
+ .title { text-align: center; margin-bottom: 2rem; }
541
+ .input-group { margin-bottom: 1.5rem; }
542
+ .help-text { font-size: 0.9em; color: #666; }
543
+ .status-area { margin: 1rem 0; }
544
+ """
545
+ ) as app:
546
+ with gr.Group(elem_classes="container"):
547
+ gr.Markdown(
548
+ """
549
+ # πŸŽ™οΈ Text to Speech Studio
550
+ ### Generate professional quality audio with synchronized subtitles
551
+ """
552
+ , elem_classes="title")
553
 
554
+ with gr.Tabs():
555
+ with gr.TabItem("πŸ“ Text Input"):
556
+ with gr.Row():
557
+ with gr.Column(scale=3):
558
+ text_input = gr.Textbox(
559
+ label="Your Text",
560
+ lines=10,
561
+ placeholder="Enter your text here. The AI will automatically segment it into natural phrases...",
562
+ elem_classes="input-group"
563
+ )
564
+ gr.Markdown(
565
+ "πŸ’‘ **Tip:** For best results, ensure proper punctuation in your text.",
566
+ elem_classes="help-text"
567
+ )
568
+
569
+ with gr.Column(scale=2):
570
+ with gr.Group():
571
+ gr.Markdown("### Voice Settings")
572
+ voice_dropdown = gr.Dropdown(
573
+ label="Voice",
574
+ choices=list(voice_options.keys()),
575
+ value="Jenny Female",
576
+ elem_classes="input-group"
577
+ )
578
+ with gr.Row():
579
+ with gr.Column():
580
+ pitch_slider = gr.Slider(
581
+ label="Pitch",
582
+ minimum=-10,
583
+ maximum=10,
584
+ value=0,
585
+ step=1,
586
+ elem_classes="input-group"
587
+ )
588
+ with gr.Column():
589
+ rate_slider = gr.Slider(
590
+ label="Speed",
591
+ minimum=-25,
592
+ maximum=25,
593
+ value=0,
594
+ step=1,
595
+ elem_classes="input-group"
596
+ )
597
+
598
+ with gr.TabItem("βš™οΈ Advanced Settings"):
599
+ with gr.Row():
600
+ with gr.Column():
601
+ words_per_line = gr.Slider(
602
+ label="Words per Line",
603
+ minimum=3,
604
+ maximum=12,
605
+ value=6,
606
+ step=1,
607
+ info="πŸ“ Controls subtitle line length",
608
+ elem_classes="input-group"
609
+ )
610
+ with gr.Column():
611
+ lines_per_segment = gr.Slider(
612
+ label="Lines per Segment",
613
+ minimum=1,
614
+ maximum=4,
615
+ value=2,
616
+ step=1,
617
+ info="πŸ“‘ Controls subtitle block size",
618
+ elem_classes="input-group"
619
+ )
620
+ with gr.Column():
621
+ parallel_processing = gr.Checkbox(
622
+ label="Parallel Processing",
623
+ value=True,
624
+ info="⚑ Faster processing for longer texts",
625
+ elem_classes="input-group"
626
+ )
627
+
628
+ with gr.Row():
629
+ with gr.Column(scale=2):
630
+ submit_btn = gr.Button(
631
+ "🎯 Generate Audio & Subtitles",
632
+ variant="primary",
633
+ scale=2
634
+ )
635
+ with gr.Column():
636
+ clear_btn = gr.Button("πŸ”„ Clear All", variant="secondary")
637
+
638
+ with gr.Group(elem_classes="status-area"):
639
+ error_output = gr.Textbox(
640
+ label="Status",
641
+ visible=False,
642
+ elem_classes="error-message"
643
  )
644
+
645
+ with gr.Tabs():
646
+ with gr.TabItem("🎧 Preview"):
647
+ audio_output = gr.Audio(
648
+ label="Generated Audio",
649
+ elem_classes="preview-audio"
650
+ )
651
+ with gr.TabItem("πŸ“₯ Downloads"):
652
+ with gr.Row():
653
+ with gr.Column():
654
+ srt_file = gr.File(
655
+ label="πŸ“„ Subtitle File (SRT)",
656
+ elem_classes="download-file"
657
+ )
658
+ with gr.Column():
659
+ audio_file = gr.File(
660
+ label="🎡 Audio File (MP3)",
661
+ elem_classes="download-file"
662
+ )
663
+
664
+ gr.Markdown(
665
+ """
666
+ ### πŸ“Œ Features
667
+ - Professional-quality text-to-speech conversion
668
+ - Automatic natural speech segmentation
669
+ - Perfectly synchronized subtitles
670
+ - Multiple voice options and customization
671
+ """,
672
+ elem_classes="help-text"
673
+ )
674
+
675
+ # Clear button functionality
676
+ def clear_inputs():
677
+ return {
678
+ text_input: "",
679
+ pitch_slider: 0,
680
+ rate_slider: 0,
681
+ voice_dropdown: "Jenny Female",
682
+ words_per_line: 6,
683
+ lines_per_segment: 2,
684
+ parallel_processing: True,
685
+ error_output: gr.update(visible=False),
686
+ audio_output: None,
687
+ srt_file: None,
688
+ audio_file: None
689
+ }
690
 
691
+ clear_btn.click(
692
+ fn=clear_inputs,
693
+ inputs=[],
694
+ outputs=[
695
+ text_input, pitch_slider, rate_slider, voice_dropdown,
696
+ words_per_line, lines_per_segment, parallel_processing,
697
+ error_output, audio_output, srt_file, audio_file
698
+ ]
699
+ )
700
+
701
+ # Existing button click handler
 
 
702
  submit_btn.click(
703
  fn=process_text_with_progress,
704
  inputs=[
705
+ text_input, pitch_slider, rate_slider, voice_dropdown,
706
+ words_per_line, lines_per_segment, parallel_processing
 
 
 
 
 
707
  ],
708
  outputs=[
709
+ srt_file, audio_file, audio_output, error_output, error_output
 
 
 
 
710
  ],
711
  api_name="generate"
712
  )