CoolFace
Apppublic

SpongeBobFan2002/openaudio-s1-mini

sourceHugging Facecc-by-nc-sa-4.0updated 1y agoView on Hugging Face
0likes
__init__.py156 linesDownload Raw Back to webui
1from typing import Callable2 3import gradio as gr4 5from fish_speech.i18n import i18n6from tools.webui.variables import HEADER_MD, TEXTBOX_PLACEHOLDER7 8 9def build_app(inference_fct: Callable, theme: str = "light") -> gr.Blocks:10    with gr.Blocks(theme=gr.themes.Base()) as app:11        gr.Markdown(HEADER_MD)12 13        # Use light theme by default14        app.load(15            None,16            None,17            js="() => {const params = new URLSearchParams(window.location.search);if (!params.has('__theme')) {params.set('__theme', '%s');window.location.search = params.toString();}}"18            % theme,19        )20 21        # Inference22        with gr.Row():23            with gr.Column(scale=3):24                text = gr.Textbox(25                    label=i18n("Input Text"), placeholder=TEXTBOX_PLACEHOLDER, lines=1026                )27 28                with gr.Row():29                    with gr.Column():30                        with gr.Tab(label=i18n("Advanced Config")):31                            with gr.Row():32                                chunk_length = gr.Slider(33                                    label=i18n("Iterative Prompt Length, 0 means off"),34                                    minimum=100,35                                    maximum=400,36                                    value=300,37                                    step=8,38                                )39 40                                max_new_tokens = gr.Slider(41                                    label=i18n(42                                        "Maximum tokens per batch, 0 means no limit"43                                    ),44                                    minimum=0,45                                    maximum=2048,46                                    value=0,47                                    step=8,48                                )49 50                            with gr.Row():51                                top_p = gr.Slider(52                                    label="Top-P",53                                    minimum=0.7,54                                    maximum=0.95,55                                    value=0.8,56                                    step=0.01,57                                )58 59                                repetition_penalty = gr.Slider(60                                    label=i18n("Repetition Penalty"),61                                    minimum=1,62                                    maximum=1.2,63                                    value=1.1,64                                    step=0.01,65                                )66 67                            with gr.Row():68                                temperature = gr.Slider(69                                    label="Temperature",70                                    minimum=0.7,71                                    maximum=1.0,72                                    value=0.8,73                                    step=0.01,74                                )75                                seed = gr.Number(76                                    label="Seed",77                                    info="0 means randomized inference, otherwise deterministic",78                                    value=0,79                                )80 81                        with gr.Tab(label=i18n("Reference Audio")):82                            with gr.Row():83                                gr.Markdown(84                                    i18n(85                                        "5 to 10 seconds of reference audio, useful for specifying speaker."86                                    )87                                )88                            with gr.Row():89                                reference_id = gr.Textbox(90                                    label=i18n("Reference ID"),91                                    placeholder="Leave empty to use uploaded references",92                                )93 94                            with gr.Row():95                                use_memory_cache = gr.Radio(96                                    label=i18n("Use Memory Cache"),97                                    choices=["on", "off"],98                                    value="on",99                                )100 101                            with gr.Row():102                                reference_audio = gr.Audio(103                                    label=i18n("Reference Audio"),104                                    type="filepath",105                                )106                            with gr.Row():107                                reference_text = gr.Textbox(108                                    label=i18n("Reference Text"),109                                    lines=1,110                                    placeholder="在一无所知中,梦里的一天结束了,一个新的「轮回」便会开始。",111                                    value="",112                                )113 114            with gr.Column(scale=3):115                with gr.Row():116                    error = gr.HTML(117                        label=i18n("Error Message"),118                        visible=True,119                    )120                with gr.Row():121                    audio = gr.Audio(122                        label=i18n("Generated Audio"),123                        type="numpy",124                        interactive=False,125                        visible=True,126                    )127 128                with gr.Row():129                    with gr.Column(scale=3):130                        generate = gr.Button(131                            value="\U0001f3a7 " + i18n("Generate"),132                            variant="primary",133                        )134 135        # Submit136        generate.click(137            inference_fct,138            [139                text,140                reference_id,141                reference_audio,142                reference_text,143                max_new_tokens,144                chunk_length,145                top_p,146                repetition_penalty,147                temperature,148                seed,149                use_memory_cache,150            ],151            [audio, error],152            concurrency_limit=1,153        )154 155    return app156