lenML/ChatTTS-Forge
301
1import logging2import os3 4import gradio as gr5 6from modules import config7from modules.webui import gradio_extensions, webui_config8from modules.webui.changelog_tab import create_changelog_tab9from modules.webui.finetune.ft_tab import create_ft_tabs10from modules.webui.localization_runtime import ENLocalizationVars, ZHLocalizationVars11from modules.webui.readme_tab import create_readme_tab12from modules.webui.speaker_tab import create_speaker_panel13from modules.webui.ssml.podcast_tab import create_ssml_podcast_tab14from modules.webui.ssml.spliter_tab import create_spliter_tab15from modules.webui.ssml.ssml_tab import create_ssml_interface16from modules.webui.system_tab import create_system_tab17from modules.webui.tts_tab import create_tts_interface18 19logger = logging.getLogger(__name__)20 21 22def webui_init():23 # fix: If the system proxy is enabled in the Windows system, you need to skip these24 os.environ["NO_PROXY"] = "localhost,127.0.0.1,0.0.0.0"25 26 if config.runtime_env_vars.language == "en":27 webui_config.localization = ENLocalizationVars()28 else:29 webui_config.localization = ZHLocalizationVars()30 31 logger.info("WebUI module initialized")32 33 34def create_app_footer():35 gradio_version = gr.__version__36 git_tag = os.environ.get("V_GIT_TAG") or config.versions.git_tag37 git_commit = os.environ.get("V_GIT_COMMIT") or config.versions.git_commit38 git_branch = os.environ.get("V_GIT_BRANCH") or config.versions.git_branch39 python_version = config.versions.python_version40 torch_version = config.versions.torch_version41 ffmpeg_version = config.versions.ffmpeg_version42 43 config.versions.gradio_version = gradio_version44 45 footer_items = ["๐ฆ [ChatTTS-Forge](https://github.com/lenML/ChatTTS-Forge)"]46 footer_items.append(47 f"version: [{git_tag}](https://github.com/lenML/ChatTTS-Forge/commit/{git_commit})"48 )49 footer_items.append(f"branch: `{git_branch}`")50 footer_items.append(f"python: `{python_version}`")51 footer_items.append(f"torch: `{torch_version}`")52 footer_items.append(f"ffmpeg: `{ffmpeg_version}`")53 54 if config.runtime_env_vars.api and not config.runtime_env_vars.no_docs:55 footer_items.append(f"[api](/docs)")56 57 gr.Markdown(58 " | ".join(footer_items),59 elem_classes=["no-translate"],60 )61 62 63def create_interface():64 gradio_extensions.reload_javascript()65 66 js_func = """67 function refresh() {68 const url = new URL(window.location);69 70 if (url.searchParams.get('__theme') !== 'dark') {71 url.searchParams.set('__theme', 'dark');72 window.location.href = url.href;73 }74 }75 """76 77 head_js = """78 <script>79 </script>80 """81 82 with gr.Blocks(js=js_func, head=head_js, title="ChatTTS Forge WebUI") as demo:83 css = """84 <style>85 .big-button {86 height: 80px;87 }88 #input_title div.eta-bar {89 display: none !important; transform: none !important;90 }91 footer {92 display: none !important;93 }94 </style>95 """96 97 gr.HTML(css)98 with gr.Tabs() as tabs:99 with gr.TabItem("TTS"):100 create_tts_interface()101 102 with gr.TabItem("SSML", id="ssml"):103 with gr.Tabs() as ssml_tabs:104 with gr.TabItem("Editor", id="ssml.editor"):105 ssml_input = create_ssml_interface()106 with gr.TabItem("Spilter"):107 create_spliter_tab(108 ssml_input=ssml_input, tabs1=tabs, tabs2=ssml_tabs109 )110 with gr.TabItem("Podcast"):111 create_ssml_podcast_tab(112 ssml_input=ssml_input, tabs1=tabs, tabs2=ssml_tabs113 )114 115 with gr.TabItem("Speaker"):116 create_speaker_panel()117 with gr.TabItem("Inpainting", visible=webui_config.experimental):118 gr.Markdown("๐ง Under construction")119 with gr.TabItem("ASR", visible=webui_config.experimental):120 gr.Markdown("๐ง Under construction")121 with gr.TabItem("Finetune", visible=webui_config.experimental):122 create_ft_tabs(demo)123 124 with gr.TabItem("System"):125 create_system_tab()126 127 with gr.TabItem("README"):128 with gr.Tabs():129 with gr.TabItem("readme"):130 create_readme_tab()131 with gr.TabItem("changelog"):132 create_changelog_tab()133 134 create_app_footer()135 136 # Dump the English config for the localization137 # ** JUST for developer138 # localization.dump_english_config(gradio_hijack.all_components)139 return demo140 