mirror of
https://github.com/2noise/ChatTTS.git
synced 2026-08-30 17:05:27 +08:00
fix(examples): ipnyb infer (#392)
This commit is contained in:
@@ -92,7 +92,9 @@ class GPT_warpper(nn.Module):
|
||||
emb_code = [self.emb_code[i](masked_input_ids[:, i]) for i in range(self.num_vq)]
|
||||
emb_code = torch.stack(emb_code, 2).sum(2)
|
||||
|
||||
emb = torch.cat((emb_text, emb_code)).unsqueeze_(0)
|
||||
emb = torch.zeros((input_ids.shape[:-1])+(emb_text.shape[-1],), device=emb_text.device, dtype=emb_text.dtype)
|
||||
emb[text_mask] = emb_text
|
||||
emb[~text_mask] = emb_code.to(emb.dtype)
|
||||
|
||||
del emb_text, emb_code
|
||||
|
||||
@@ -263,10 +265,10 @@ class GPT_warpper(nn.Module):
|
||||
if not infer_text:
|
||||
# logits = rearrange(logits, "b c n -> (b n) c")
|
||||
logits = logits.permute(0, 2, 1)
|
||||
logits = logits.view(-1, logits.size(2))
|
||||
logits = logits.reshape(-1, logits.size(2))
|
||||
# logits_token = rearrange(inputs_ids[:, start_idx:], "b c n -> (b n) c")
|
||||
inputs_ids_sliced = inputs_ids[:, start_idx:].permute(0, 2, 1)
|
||||
logits_token = inputs_ids_sliced.view(
|
||||
logits_token = inputs_ids_sliced.reshape(
|
||||
inputs_ids_sliced.size(0)*inputs_ids_sliced.size(1), -1,
|
||||
)
|
||||
else:
|
||||
|
||||
Vendored
+16
-3
@@ -13,8 +13,19 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os, sys\n",
|
||||
"\n",
|
||||
"if sys.platform == \"darwin\":\n",
|
||||
" os.environ[\"PYTORCH_ENABLE_MPS_FALLBACK\"] = \"1\"\n",
|
||||
"\n",
|
||||
"if not \"root_dir\" in globals():\n",
|
||||
" now_dir = os.getcwd() # skip examples/ipynb\n",
|
||||
" root_dir = os.path.join(now_dir, \"../../\")\n",
|
||||
" sys.path.append(root_dir)\n",
|
||||
" print(\"init root dir to\", root_dir)\n",
|
||||
"\n",
|
||||
"from dotenv import load_dotenv\n",
|
||||
"load_dotenv(\"sha256.env\")\n",
|
||||
"load_dotenv(os.path.join(root_dir, \"sha256.env\"))\n",
|
||||
"\n",
|
||||
"import torch\n",
|
||||
"torch._dynamo.config.cache_size_limit = 64\n",
|
||||
@@ -38,6 +49,8 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"os.chdir(root_dir)\n",
|
||||
"\n",
|
||||
"chat = ChatTTS.Chat()\n",
|
||||
"chat.load_models()\n",
|
||||
"\n",
|
||||
@@ -70,7 +83,7 @@
|
||||
"source": [
|
||||
"texts = [\"So we found being competitive and collaborative was a huge way of staying motivated towards our goals, so one person to call when you fall off, one person who gets you back on then one person to actually do the activity with.\",]*3 \\\n",
|
||||
" + [\"我觉得像我们这些写程序的人,他,我觉得多多少少可能会对开源有一种情怀在吧我觉得开源是一个很好的形式。现在其实最先进的技术掌握在一些公司的手里的话,就他们并不会轻易的开放给所有的人用。\"]*3 \n",
|
||||
" \n",
|
||||
"\n",
|
||||
"wavs = chat.infer(texts)"
|
||||
]
|
||||
},
|
||||
@@ -239,7 +252,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.8"
|
||||
"version": "3.9.6"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
@@ -116,10 +116,10 @@ def generate_audio_stream(text, temperature, top_P, top_K, audio_seed_input, tex
|
||||
def main():
|
||||
|
||||
with gr.Blocks() as demo:
|
||||
gr.Markdown("# ChatTTS Webui")
|
||||
gr.Markdown("ChatTTS Model: [2noise/ChatTTS](https://github.com/2noise/ChatTTS)")
|
||||
gr.Markdown("# ChatTTS WebUI")
|
||||
gr.Markdown("> ChatTTS Model: [2noise/ChatTTS](https://github.com/2noise/ChatTTS)")
|
||||
|
||||
default_text = "四川美食确实以辣闻名,但也有不辣的选择。[uv_break]比如甜水面、赖汤圆、蛋烘糕、叶儿粑等,这些小吃口味温和,甜而不腻,也很受欢迎。[laugh]"
|
||||
default_text = "四川美食确实以辣闻名,但也有不辣的选择。比如甜水面、赖汤圆、蛋烘糕、叶儿粑等,这些小吃口味温和,甜而不腻,也很受欢迎。"
|
||||
text_input = gr.Textbox(label="Input Text", lines=4, placeholder="Please Input Text...", value=default_text)
|
||||
|
||||
with gr.Row():
|
||||
|
||||
Reference in New Issue
Block a user