Skip to content

Commit

Permalink
♻️ webui refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
zhzLuke96 committed Jun 7, 2024
1 parent 13eb1c5 commit 7585282
Show file tree
Hide file tree
Showing 15 changed files with 988 additions and 856 deletions.
7 changes: 7 additions & 0 deletions modules/denoise.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from audio_denoiser.AudioDenoiser import AudioDenoiser
import torch
import torchaudio


class TTSAudioDenoiser:
pass
14 changes: 14 additions & 0 deletions modules/hf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 给huggingface space写的兼容代码

try:
import spaces
except:

class NoneSpaces:
def __init__(self):
pass

def GPU(self, fn):
return fn

spaces = NoneSpaces()
Empty file added modules/webui/__init__.py
Empty file.
110 changes: 110 additions & 0 deletions modules/webui/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import logging
import os

import torch
import gradio as gr

from modules import config

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)

if config.runtime_env_vars.webui_experimental:
with gr.TabItem("Speaker"):
create_speaker_panel()
with gr.TabItem("Denoise"):
gr.Markdown("🚧 Under construction")
with gr.TabItem("Inpainting"):
gr.Markdown("🚧 Under construction")
with gr.TabItem("ASR"):
gr.Markdown("🚧 Under construction")

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

create_app_footer()
return demo
Empty file added modules/webui/asr_tab.py
Empty file.
5 changes: 5 additions & 0 deletions modules/webui/denoise_tab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import gradio as gr


def create_denoise_tab():
pass
164 changes: 164 additions & 0 deletions modules/webui/examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
example_texts = [
{
"text": "大🍌,一条大🍌,嘿,你的感觉真的很奇妙 [lbreak]",
},
{"text": "Big 🍌, a big 🍌, hey, your feeling is really wonderful [lbreak]"},
{
"text": """
# 这是 markdown 标题
```
代码块将跳过
```
- **文本标准化**:
- **Markdown**: 自动检测处理 markdown 格式文本。
- **数字转写**: 自动将数字转为模型可识别的文本。
- **Emoji 适配**: 自动翻译 emoji 为可读文本。
- **基于分词器**: 基于 tokenizer 预处理文本,覆盖模型所有不支持字符范围。
- **中英文识别**: 适配英文环境。
"""
},
{
"text": "天气预报显示,今天会有小雨,请大家出门时记得带伞。降温的天气也提醒我们要适时添衣保暖 [lbreak]",
},
{
"text": "公司的年度总结会议将在下周三举行,请各部门提前准备好相关材料,确保会议顺利进行 [lbreak]",
},
{
"text": "今天的午餐菜单包括烤鸡、沙拉和蔬菜汤,大家可以根据自己的口味选择适合的菜品 [lbreak]",
},
{
"text": "请注意,电梯将在下午两点进行例行维护,预计需要一个小时的时间,请大家在此期间使用楼梯 [lbreak]",
},
{
"text": "图书馆新到了一批书籍,涵盖了文学、科学和历史等多个领域,欢迎大家前来借阅 [lbreak]",
},
{
"text": "电影中梁朝伟扮演的陈永仁的编号27149 [lbreak]",
},
{
"text": "这块黄金重达324.75克 [lbreak]",
},
{
"text": "我们班的最高总分为583分 [lbreak]",
},
{
"text": "12~23 [lbreak]",
},
{
"text": "-1.5~2 [lbreak]",
},
{
"text": "她出生于86年8月18日,她弟弟出生于1995年3月1日 [lbreak]",
},
{
"text": "等会请在12:05请通知我 [lbreak]",
},
{
"text": "今天的最低气温达到-10°C [lbreak]",
},
{
"text": "现场有7/12的观众投出了赞成票 [lbreak]",
},
{
"text": "明天有62%的概率降雨 [lbreak]",
},
{
"text": "随便来几个价格12块5,34.5元,20.1万 [lbreak]",
},
{
"text": "这是固话0421-33441122 [lbreak]",
},
{
"text": "这是手机+86 18544139121 [lbreak]",
},
]

ssml_example1 = """
<speak version="0.1">
<voice spk="Bob" seed="42" style="narration-relaxed">
下面是一个 ChatTTS 用于合成多角色多情感的有声书示例[lbreak]
</voice>
<voice spk="Bob" seed="42" style="narration-relaxed">
黛玉冷笑道:[lbreak]
</voice>
<voice spk="female2" seed="42" style="angry">
我说呢 [uv_break] ,亏了绊住,不然,早就飞起来了[lbreak]
</voice>
<voice spk="Bob" seed="42" style="narration-relaxed">
宝玉道:[lbreak]
</voice>
<voice spk="Alice" seed="42" style="unfriendly">
“只许和你玩 [uv_break] ,替你解闷。不过偶然到他那里,就说这些闲话。”[lbreak]
</voice>
<voice spk="female2" seed="42" style="angry">
“好没意思的话![uv_break] 去不去,关我什么事儿? 又没叫你替我解闷儿 [uv_break],还许你不理我呢” [lbreak]
</voice>
<voice spk="Bob" seed="42" style="narration-relaxed">
说着,便赌气回房去了 [lbreak]
</voice>
</speak>
"""
ssml_example2 = """
<speak version="0.1">
<voice spk="Bob" seed="42" style="narration-relaxed">
使用 prosody 控制生成文本的语速语调和音量,示例如下 [lbreak]
<prosody>
无任何限制将会继承父级voice配置进行生成 [lbreak]
</prosody>
<prosody rate="1.5">
设置 rate 大于1表示加速,小于1为减速 [lbreak]
</prosody>
<prosody pitch="6">
设置 pitch 调整音调,设置为6表示提高6个半音 [lbreak]
</prosody>
<prosody volume="2">
设置 volume 调整音量,设置为2表示提高2个分贝 [lbreak]
</prosody>
在 voice 中无prosody包裹的文本即为默认生成状态下的语音 [lbreak]
</voice>
</speak>
"""
ssml_example3 = """
<speak version="0.1">
<voice spk="Bob" seed="42" style="narration-relaxed">
使用 break 标签将会简单的 [lbreak]
<break time="500" />
插入一段空白到生成结果中 [lbreak]
</voice>
</speak>
"""

ssml_example4 = """
<speak version="0.1">
<voice spk="Bob" seed="42" style="excited">
temperature for sampling (may be overridden by style or speaker) [lbreak]
<break time="500" />
温度值用于采样,这个值有可能被 style 或者 speaker 覆盖 [lbreak]
<break time="500" />
temperature for sampling ,这个值有可能被 style 或者 speaker 覆盖 [lbreak]
<break time="500" />
温度值用于采样,(may be overridden by style or speaker) [lbreak]
</voice>
</speak>
"""

ssml_examples = [
ssml_example1,
ssml_example2,
ssml_example3,
ssml_example4,
]

default_ssml = """
<speak version="0.1">
<voice spk="Bob" seed="42" style="narration-relaxed">
这里是一个简单的 SSML 示例 [lbreak]
</voice>
</speak>
"""
13 changes: 13 additions & 0 deletions modules/webui/readme_tab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import gradio as gr


def read_local_readme():
with open("README.md", "r", encoding="utf-8") as file:
content = file.read()
content = content[content.index("# ") :]
return content


def create_readme_tab():
readme_content = read_local_readme()
gr.Markdown(readme_content)
13 changes: 13 additions & 0 deletions modules/webui/speaker_tab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import gradio as gr

from modules.webui.webui_utils import get_speakers


# 显示 a b c d 四个选择框,选择一个或多个,然后可以试音,并导出
def create_speaker_panel():
speakers = get_speakers()

def get_speaker_show_name(spk):
pass

gr.Markdown("🚧 Under construction")
Loading

0 comments on commit 7585282

Please sign in to comment.