Spaces:
Build error
Build error
| import gradio as gr | |
| import torch | |
| from espnet2.bin.tts_inference import Text2Speech | |
| from espnet_model_zoo.downloader import ModelDownloader | |
| from transformers import AutoTokenizer | |
| # تحميل قائمة التوكينات | |
| with open('tokens.txt', 'r', encoding='utf-8') as f: | |
| token_list = [line.strip() for line in f] | |
| # تحميل النموذج المدرب | |
| model_path = 'exp/tts_fastspeech2/train.total_count.ave_10best.pth' # تأكد من مسار النموذج الصحيح | |
| config_path = 'exp/tts_fastspeech2/config.yaml' | |
| # إعداد Text2Speech | |
| device = 'cuda' if torch.cuda.is_available() else 'cpu' | |
| text2speech = Text2Speech.from_pretrained( | |
| model_file=model_path, | |
| config_file=config_path, | |
| device=device, | |
| threshold=0.5, | |
| maxlenratio=10.0, | |
| minlenratio=0.0, | |
| use_att_constraint=False, | |
| backward_window=1, | |
| forward_window=3, | |
| ) | |
| # دالة لتحويل النص إلى كلام | |
| def tts_najdi(text): | |
| with torch.no_grad(): | |
| wav = text2speech(text)["wav"] | |
| return wav.view(-1).cpu().numpy(), 22050 # تأكد من استخدام معدل العينة الصحيح | |
| # واجهة Gradio | |
| iface = gr.Interface(fn=tts_najdi, inputs="text", outputs="audio", title="Najdi TTS Model") | |
| iface.launch(server_name="0.0.0.0", server_port=7860) | |