001 stream
Browse files
app.py
CHANGED
@@ -38,11 +38,81 @@ head = '''
|
|
38 |
<script type="module">
|
39 |
import { matcha_tts,env } from "https://akjava.github.io/Matcha-TTS-Japanese/js-esm/v001-20240921/matcha_tts_onnx_en.js";
|
40 |
window.MatchaTTSEn = matcha_tts
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
}
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
</script>
|
47 |
'''
|
48 |
|
@@ -53,10 +123,11 @@ with gr.Blocks(title="LLM with TTS",head=head) as demo:
|
|
53 |
|
54 |
js = """
|
55 |
function(chatbot){
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
60 |
}
|
61 |
"""
|
62 |
chatbot = gr.Chatbot(type="messages")
|
@@ -90,6 +161,6 @@ with gr.Blocks(title="LLM with TTS",head=head) as demo:
|
|
90 |
msg.submit(call_generate_text, [msg, chatbot], [msg, chatbot])
|
91 |
|
92 |
import os
|
93 |
-
|
94 |
-
|
95 |
-
demo.launch(allowed_paths=["
|
|
|
38 |
<script type="module">
|
39 |
import { matcha_tts,env } from "https://akjava.github.io/Matcha-TTS-Japanese/js-esm/v001-20240921/matcha_tts_onnx_en.js";
|
40 |
window.MatchaTTSEn = matcha_tts
|
41 |
+
</script>
|
42 |
+
|
43 |
+
<script>
|
44 |
+
let last_chatbot_size = 0
|
45 |
+
let tts_text_index = 0
|
46 |
+
let tts_texts = []
|
47 |
+
|
48 |
+
const interval = 100
|
49 |
+
async function start_multi_line_tts() {
|
50 |
+
//console.log("start_multi_line_tts")
|
51 |
+
//console.log(tts_texts.length)
|
52 |
+
if (tts_texts.length > tts_text_index){
|
53 |
+
const tts_text = tts_texts[tts_text_index]
|
54 |
+
tts_text_index += 1
|
55 |
+
console.log(tts_text)
|
56 |
+
if (tts_text!=""){
|
57 |
+
await window.MatchaTTSEn(tts_text,"/file=models/ljspeech_sim.onnx")
|
58 |
+
}
|
59 |
+
|
60 |
+
|
61 |
+
}
|
62 |
+
setTimeout(start_multi_line_tts, interval);
|
63 |
+
}
|
64 |
+
|
65 |
+
|
66 |
+
function reset_tts_text(){
|
67 |
+
console.log("reset tts text")
|
68 |
+
tts_text_index = 0
|
69 |
+
tts_texts = []
|
70 |
+
}
|
71 |
+
function replaceSpecialChars(text) {
|
72 |
+
const pattern = /[^a-zA-Z0-9,.!?-_']/g;
|
73 |
+
return text.replace(pattern, ' ');
|
74 |
+
}
|
75 |
+
|
76 |
+
|
77 |
+
function update_tts_texts(text){
|
78 |
+
//console.log(text)
|
79 |
+
const replaced_text = replaceSpecialChars(text)
|
80 |
+
const new_texts = []
|
81 |
+
const splited = replaced_text.split(/[.!?]+\s/);
|
82 |
+
for (let i = 0; i < splited.length; i++) {
|
83 |
+
const value = splited[i].trim();
|
84 |
+
|
85 |
+
if (i === splited.length - 1) {
|
86 |
+
if (value.endsWith(".") || value.endsWith("?") || value.endsWith("!")){
|
87 |
+
new_texts.push(value);
|
88 |
}
|
89 |
+
console.log("Last element:", value);
|
90 |
+
} else {
|
91 |
+
// その他の要素に対する処理
|
92 |
+
new_texts.push(value);
|
93 |
+
}
|
94 |
+
}
|
95 |
+
tts_texts=new_texts
|
96 |
+
|
97 |
+
}
|
98 |
+
|
99 |
+
function update_chatbot(chatbot){
|
100 |
+
//console.log(chatbot)
|
101 |
+
if (chatbot.length!=last_chatbot_size){
|
102 |
+
last_chatbot_size = chatbot.length
|
103 |
+
reset_tts_text()
|
104 |
+
}
|
105 |
+
text = (chatbot[chatbot.length -1])["content"]
|
106 |
+
update_tts_texts(text)
|
107 |
+
|
108 |
+
}
|
109 |
+
|
110 |
+
window.replaceSpecialChars = replaceSpecialChars
|
111 |
+
|
112 |
+
window.update_chatbot = update_chatbot
|
113 |
+
window.update_tts_texts = update_tts_texts
|
114 |
+
window.reset_tts_text = reset_tts_text
|
115 |
+
start_multi_line_tts();
|
116 |
</script>
|
117 |
'''
|
118 |
|
|
|
123 |
|
124 |
js = """
|
125 |
function(chatbot){
|
126 |
+
window.update_chatbot(chatbot)
|
127 |
+
//text = (chatbot[chatbot.length -1])["content"]
|
128 |
+
//tts_text = window.replaceSpecialChars(text)
|
129 |
+
//console.log(tts_text)
|
130 |
+
//window.MatchaTTSEn(tts_text,"/file=models/ljspeech_sim.onnx")
|
131 |
}
|
132 |
"""
|
133 |
chatbot = gr.Chatbot(type="messages")
|
|
|
161 |
msg.submit(call_generate_text, [msg, chatbot], [msg, chatbot])
|
162 |
|
163 |
import os
|
164 |
+
dir ="/home/user/app/"
|
165 |
+
dir = "C:\\Users\\owner\\Documents\\pythons\\huggingface\\mistral-7b-v0.3-matcha-tts-en"
|
166 |
+
demo.launch(allowed_paths=[os.path.join(dir,"models","ljspeech_sim.onnx")])
|