File size: 3,822 Bytes
1fec5bf
2da20a0
1fec5bf
 
 
 
 
de8ee7d
 
 
2f9d246
 
 
1fec5bf
30903c6
1fec5bf
 
 
b5439d2
1fec5bf
 
 
 
 
 
 
 
 
fca3fec
2f9d246
1fec5bf
 
d8b49f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a38869
 
d8b49f1
 
 
 
 
 
 
 
 
 
 
63b4244
 
 
 
d8b49f1
 
 
2f9d246
2c1e472
2f9d246
 
 
728bf18
 
2f9d246
 
 
 
1fec5bf
 
 
 
 
 
 
70968b9
1fec5bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ca7898e
 
1fec5bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de8ee7d
1fec5bf
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import os
import spaces
import gradio as gr
import tempfile
from importlib.resources import files
from silma_tts.api import SilmaTTS


CURR_BASE_DIR = os.getcwd()

print("Loading SILMA TTS model...", flush=True)
silma_tts = SilmaTTS()


@spaces.GPU(duration=120)
def do_inference(ref_audio, ref_text, gen_text):
    if not ref_audio:
        return None

    _, output_wav_path = tempfile.mkstemp(suffix=".wav")

    wav, sr, _ = silma_tts.infer(
        ref_file=ref_audio,
        ref_text=ref_text,
        gen_text=gen_text,
        file_wave=output_wav_path,
    )


    return output_wav_path



custom_css = """
    .gradio-container{
        background-color: unset;
    }
    input, textarea {
        font-family: 'Noto Naskh Arabic', 'Arial', sans-serif !important;
    }

    button.secondary:hover{
        background-color:steelblue !important;
        color:white;
    }
   
    #tool-header{
        padding:0px 0px 0px 0px !important;
        font-family: sans-serif;
    }
    #tool-header h1{
        display: flex;
        align-items: center;
    }
    #tool-header img{
        width: 80px;
        display: inline-block;
        margin-right: 10px;
        border-radius: 5px;
    }

    .gradio-style a{
        padding: 0px !important;
    }
"""

with gr.Blocks(css=custom_css) as demo:

    gr.HTML(
        f"""<h1><img src='/gradio_api/file={CURR_BASE_DIR}/images/silma-logo.png'/>SILMA TTS Demo</h1>
        <br>
        <p style="font-size:16px">
            SILMA TTS v1 is a high-performance, 150M-parameter bilingual (Arabic/English) TTS model developed by <a href="https://silma.ai">SILMA.AI</a>.    
            Check out the <a href="https://huggingface.co/silma-ai/silma-tts" target="_blank">model page</a> or explore the repository on <a href="https://github.com/SILMA-AI/silma-tts" target="_blank">Github</a> for more details.
        </p>
        """,
        elem_id="tool-header"
    )
    
    with gr.Row():
        with gr.Column():
            # Define inputs
            ref_audio_input = gr.Audio(
                label="Reference Audio", 
                type="filepath", 
                value="ar.ref.24k.wav"
            )
            ref_text_input = gr.Textbox(
                label="Reference Text", 
                value="ูˆูŠุฏู‚ู‚ ุงู„ู†ุธุฑ ููŠ ุงู„ู‚ุฑุขู† ุงู„ูƒุฑูŠู… ูˆุณุงุฆุฑ ุงู„ูƒุชุจ ุงู„ุณู…ุงูˆูŠุฉ ูˆูŠุชุจุน ู…ุณุงู„ูƒ ุงู„ุฑุณู„ ุงู„ุนุธุงู… ุนู„ูŠู‡ู… ุงู„ุตู„ุงุฉ ูˆุงู„ุณู„ุงู…."
            )
            gen_text_input = gr.Textbox(
                label="Generation Text", 
                lines=5,
                value="""
ุฃู†ุง ู†ู…ูˆุฐุฌ ุฌุฏูŠุฏ ู…ู† ุณู„ู…ู‰ ู„ุชุญูˆูŠู„ ุงู„ู†ุต ุฅู„ู‰ ูƒู„ุงู…ุŒ ูŠู…ูƒู†ู†ูŠ ุงู„ุชุญุฏุซ ุจุงู„ู„ุบุฉ ุงู„ุนุฑุจูŠุฉ ู…ุน ุฃูˆ ุจุฏูˆู† ุนู„ุงู…ุงุช ุงู„ุชุดูƒูŠู„.
I am the new SILMA model for converting text to speech, I can speak Arabic with or without diacritics.
""".strip()
            )
            submit_btn = gr.Button("Generate Speech")
            
        with gr.Column():
            audio_output = gr.Audio(label="Generated Speech")


    gr.Markdown("Note: enter text without diacritics, and our model will add them automatically. If you include full Tashkeel, auto-diacritization is disabled to preserve your original input")

    # When ref_audio_input changes, we update ref_text_input with an empty string
    ref_audio_input.input(
        fn=lambda: "", 
        inputs=None, 
        outputs=ref_text_input
    )
    
    # Set up the click event for the button
    submit_btn.click(
        fn=do_inference,
        inputs=[ref_audio_input, ref_text_input, gen_text_input],
        outputs=audio_output
    )

def main():
    print("Starting app...")

    demo.queue().launch(ssr_mode=False, allowed_paths=[CURR_BASE_DIR+"/images/"])

if __name__ == "__main__":
    main()