File size: 3,205 Bytes
374f426
 
 
 
 
 
 
da8d589
374f426
da8d589
374f426
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da8d589
 
 
 
 
 
 
 
 
374f426
 
 
 
 
 
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
import logging
import os

import torch
import gradio as gr

from modules import config
from modules.webui import webui_config

from modules.webui.system_tab import create_system_tab
from modules.webui.tts_tab import create_tts_interface
from modules.webui.ssml_tab import create_ssml_interface
from modules.webui.spliter_tab import create_spliter_tab
from modules.webui.speaker_tab import create_speaker_panel
from modules.webui.readme_tab import create_readme_tab

logger = logging.getLogger(__name__)

logging.basicConfig(
    level=os.getenv("LOG_LEVEL", "INFO"),
    format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)


def webui_init():
    # fix: If the system proxy is enabled in the Windows system, you need to skip these
    os.environ["NO_PROXY"] = "localhost,127.0.0.1,0.0.0.0"

    torch._dynamo.config.cache_size_limit = 64
    torch._dynamo.config.suppress_errors = True
    torch.set_float32_matmul_precision("high")

    logger.info("WebUI module initialized")


def create_app_footer():
    gradio_version = gr.__version__
    git_tag = config.versions.git_tag
    git_commit = config.versions.git_commit
    git_branch = config.versions.git_branch
    python_version = config.versions.python_version
    torch_version = config.versions.torch_version

    config.versions.gradio_version = gradio_version

    gr.Markdown(
        f"""
🍦 [ChatTTS-Forge](https://github.com/lenML/ChatTTS-Forge)
version: [{git_tag}](https://github.com/lenML/ChatTTS-Forge/commit/{git_commit}) | branch: `{git_branch}` | python: `{python_version}` | torch: `{torch_version}`
        """
    )


def create_interface():

    js_func = """
    function refresh() {
        const url = new URL(window.location);

        if (url.searchParams.get('__theme') !== 'dark') {
            url.searchParams.set('__theme', 'dark');
            window.location.href = url.href;
        }
    }
    """

    head_js = """
    <script>
    </script>
    """

    with gr.Blocks(js=js_func, head=head_js, title="ChatTTS Forge WebUI") as demo:
        css = """
        <style>
        .big-button {
            height: 80px;
        }
        #input_title div.eta-bar {
            display: none !important; transform: none !important;
        }
        footer {
            display: none !important;
        }
        </style>
        """

        gr.HTML(css)
        with gr.Tabs() as tabs:
            with gr.TabItem("TTS"):
                create_tts_interface()

            with gr.TabItem("SSML", id="ssml"):
                ssml_input = create_ssml_interface()

            with gr.TabItem("Spilter"):
                create_spliter_tab(ssml_input, tabs=tabs)

            with gr.TabItem("Speaker"):
                create_speaker_panel()
            with gr.TabItem("Inpainting", visible=webui_config.experimental):
                gr.Markdown("🚧 Under construction")
            with gr.TabItem("ASR", visible=webui_config.experimental):
                gr.Markdown("🚧 Under construction")

            with gr.TabItem("System"):
                create_system_tab()

            with gr.TabItem("README"):
                create_readme_tab()

        create_app_footer()
    return demo