Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,39 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
|
|
2 |
from espnet2.bin.tts_inference import Text2Speech
|
3 |
-
from
|
|
|
4 |
|
5 |
-
# تحميل
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
# تحميل
|
10 |
-
|
|
|
11 |
|
12 |
-
#
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
# دالة لتحويل النص إلى كلام
|
19 |
def tts_najdi(text):
|
20 |
-
|
21 |
-
|
22 |
-
return
|
23 |
|
24 |
# واجهة Gradio
|
25 |
-
iface = gr.Interface(fn=tts_najdi, inputs="text", outputs="audio", title="
|
26 |
iface.launch()
|
|
|
1 |
+
# app.py
|
2 |
+
|
3 |
import gradio as gr
|
4 |
+
import torch
|
5 |
from espnet2.bin.tts_inference import Text2Speech
|
6 |
+
from espnet_model_zoo.downloader import ModelDownloader
|
7 |
+
from transformers import AutoTokenizer
|
8 |
|
9 |
+
# تحميل قائمة التوكينات
|
10 |
+
with open('tokens.txt', 'r', encoding='utf-8') as f:
|
11 |
+
token_list = [line.strip() for line in f]
|
12 |
|
13 |
+
# تحميل النموذج المدرب
|
14 |
+
model_path = 'exp/tts_fastspeech2/train.total_count.ave_10best.pth' # تأكد من مسار النموذج الصحيح
|
15 |
+
config_path = 'exp/tts_fastspeech2/config.yaml'
|
16 |
|
17 |
+
# إعداد Text2Speech
|
18 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
19 |
+
text2speech = Text2Speech.from_pretrained(
|
20 |
+
model_file=model_path,
|
21 |
+
config_file=config_path,
|
22 |
+
device=device,
|
23 |
+
threshold=0.5,
|
24 |
+
maxlenratio=10.0,
|
25 |
+
minlenratio=0.0,
|
26 |
+
use_att_constraint=False,
|
27 |
+
backward_window=1,
|
28 |
+
forward_window=3,
|
29 |
+
)
|
30 |
|
31 |
# دالة لتحويل النص إلى كلام
|
32 |
def tts_najdi(text):
|
33 |
+
with torch.no_grad():
|
34 |
+
wav = text2speech(text)["wav"]
|
35 |
+
return wav.view(-1).cpu().numpy(), 22050 # تأكد من استخدام معدل العينة الصحيح
|
36 |
|
37 |
# واجهة Gradio
|
38 |
+
iface = gr.Interface(fn=tts_najdi, inputs="text", outputs="audio", title="Najdi TTS Model")
|
39 |
iface.launch()
|