Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 534 |
|
| 535 |
-
with gr.
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 580 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 581 |
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 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 |
-
|
| 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 |
)
|