Spaces:
Paused
Paused
| import html | |
| import gradio as gr | |
| from fish_speech.i18n import i18n | |
| from model import DEFAULT_REF_PATH, DEFAULT_REF_TEXT | |
| from typing import Callable | |
| DEFAULT_GEN_TEXT = "Now let's make my mum's favourite. So three mars bars into the pan. Then we add the tuna and just stir for a bit, just let the chocolate and fish infuse. A sprinkle of olive oil and some tomato ketchup. Now smell that. Oh boy this is going to be incredible." | |
| TEXTBOX_PLACEHOLDER = """Put your text here. 在此处输入文本.""" | |
| HEADER_MD = """# OpenAudio S1 | |
| ## The demo in this space is OpenAudio S1, Please check [Fish Audio](https://fish.audio) for the best model. | |
| ## 该 Demo 为 OpenAudio S1 版本, 请在 [Fish Audio](https://fish.audio) 体验最新 DEMO. | |
| A text-to-speech model based on DAC & Qwen3 developed by [Fish Audio](https://fish.audio). | |
| 由 [Fish Audio](https://fish.audio) 研发的 DAC & Qwen3 多语种语音合成. | |
| You can find the source code [here](https://github.com/fishaudio/fish-speech) and models [here](https://huggingface.co/fishaudio/openaudio-s1-mini). | |
| 你可以在 [这里](https://github.com/fishaudio/fish-speech) 找到源代码和 [这里](https://huggingface.co/fishaudio/openaudio-s1-mini) 找到模型. | |
| Related code and weights are released under CC BY-NC-SA 4.0 License. | |
| 相关代码,权重使用 CC BY-NC-SA 4.0 许可证发布. | |
| We are not responsible for any misuse of the model, please consider your local laws and regulations before using it. | |
| 我们不对模型的任何滥用负责,请在使用之前考虑您当地的法律法规. | |
| The model running in this WebUI is OpenAudio S1 Mini. | |
| 在此 WebUI 中运行的模型是 OpenAudio S1 Mini. | |
| """ | |
| def build_html_error_message(error): | |
| return f""" | |
| <div style="color: red; | |
| font-weight: bold;"> | |
| {html.escape(str(error))} | |
| </div> | |
| """ | |
| def build_app(inference_fct: Callable, theme: str = "light") -> gr.Blocks: | |
| with gr.Blocks(theme=gr.themes.Base()) as app: | |
| gr.Markdown(HEADER_MD) | |
| # Use light theme by default | |
| app.load( | |
| None, | |
| None, | |
| js="() => {const params = new URLSearchParams(window.location.search);if (!params.has('__theme')) {params.set('__theme', '%s');window.location.search = params.toString();}}" | |
| % theme, | |
| ) | |
| # Inference | |
| with gr.Row(): | |
| with gr.Column(scale=3): | |
| text = gr.Textbox( | |
| label=i18n("Input Text"), | |
| placeholder=TEXTBOX_PLACEHOLDER, | |
| lines=10, | |
| value= DEFAULT_GEN_TEXT | |
| ) | |
| with gr.Row(): | |
| with gr.Column(): | |
| with gr.Tab(label=i18n("Advanced Config")): | |
| with gr.Row(): | |
| chunk_length = gr.Slider( | |
| label=i18n("Iterative Prompt Length, 0 means off"), | |
| minimum=0, | |
| maximum=500, | |
| value=0, | |
| step=8, | |
| ) | |
| max_new_tokens = gr.Slider( | |
| label=i18n( | |
| "Maximum tokens per batch, 0 means no limit" | |
| ), | |
| minimum=0, | |
| maximum=2048, | |
| value=0, | |
| step=8, | |
| ) | |
| with gr.Row(): | |
| top_p = gr.Slider( | |
| label="Top-P", | |
| minimum=0.7, | |
| maximum=0.95, | |
| value=0.9, | |
| step=0.01, | |
| ) | |
| repetition_penalty = gr.Slider( | |
| label=i18n("Repetition Penalty"), | |
| minimum=1, | |
| maximum=1.2, | |
| value=1.1, | |
| step=0.01, | |
| ) | |
| with gr.Row(): | |
| temperature = gr.Slider( | |
| label="Temperature", | |
| minimum=0.7, | |
| maximum=1.0, | |
| value=0.9, | |
| step=0.01, | |
| ) | |
| seed = gr.Number( | |
| label="Seed", | |
| info="0 means randomized inference, otherwise deterministic", | |
| value=0, | |
| ) | |
| with gr.Tab(label=i18n("Reference Audio")): | |
| with gr.Row(): | |
| gr.Markdown( | |
| i18n( | |
| "5 to 10 seconds of reference audio, useful for specifying speaker." | |
| ) | |
| ) | |
| with gr.Row(): | |
| reference_id = gr.Textbox( | |
| label=i18n("Reference ID"), | |
| placeholder="Leave empty to use uploaded references", | |
| ) | |
| with gr.Row(): | |
| use_memory_cache = gr.Radio( | |
| label=i18n("Use Memory Cache"), | |
| choices=["on", "off"], | |
| value="on", | |
| ) | |
| with gr.Row(): | |
| reference_audio = gr.Audio( | |
| label=i18n("Reference Audio"), | |
| type="filepath", | |
| value= DEFAULT_REF_PATH, | |
| ) | |
| with gr.Row(): | |
| reference_text = gr.Textbox( | |
| label=i18n("Reference Text"), | |
| lines=1, | |
| value=DEFAULT_REF_TEXT, | |
| ) | |
| with gr.Column(scale=3): | |
| with gr.Row(): | |
| error = gr.HTML( | |
| label=i18n("Error Message"), | |
| visible=True, | |
| ) | |
| with gr.Row(): | |
| audio = gr.Audio( | |
| label=i18n("Generated Audio"), | |
| type="numpy", | |
| interactive=False, | |
| visible=True, | |
| ) | |
| with gr.Row(): | |
| with gr.Column(scale=3): | |
| generate = gr.Button( | |
| value="\U0001f3a7 " + i18n("Generate"), | |
| variant="primary", | |
| ) | |
| # Submit | |
| generate.click( | |
| inference_fct, | |
| [ | |
| text, | |
| reference_id, | |
| reference_audio, | |
| reference_text, | |
| max_new_tokens, | |
| chunk_length, | |
| top_p, | |
| repetition_penalty, | |
| temperature, | |
| seed, | |
| use_memory_cache, | |
| ], | |
| [audio, error], | |
| concurrency_limit=1, | |
| ) | |
| return app |