mohamed101020 commited on
Commit
bc5ef40
·
verified ·
1 Parent(s): 888bd0a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fairseq.checkpoint_utils import load_model_ensemble_and_task_from_hf_hub
2
+ from fairseq.models.text_to_speech.hub_interface import TTSHubInterface
3
+ import gradio as gr
4
+ import torchaudio
5
+
6
+ # تحميل النموذج مرة واحدة
7
+ models, cfg, task = load_model_ensemble_and_task_from_hf_hub(
8
+ "facebook/tts_transformer-ar-cv7",
9
+ arg_overrides={"vocoder": "hifigan", "fp16": False}
10
+ )
11
+ model = models[0]
12
+ TTSHubInterface.update_cfg_with_data_cfg(cfg, task.data_cfg)
13
+ generator = task.build_generator(model, cfg)
14
+
15
+ def synthesize(text):
16
+ sample = TTSHubInterface.get_model_input(task, text)
17
+ wav, rate = TTSHubInterface.get_prediction(task, model, generator, sample)
18
+ # حفظ الملف مؤقتًا
19
+ path = "output.wav"
20
+ torchaudio.save(path, wav.unsqueeze(0), rate)
21
+ return path
22
+
23
+ interface = gr.Interface(
24
+ fn=synthesize,
25
+ inputs=gr.Textbox(label="أدخل نصاً باللغة العربية"),
26
+ outputs=gr.Audio(label="الناتج الصوتي"),
27
+ title="تحويل النص إلى صوت بالعربية",
28
+ description="باستخدام النموذج: facebook/tts_transformer-ar-cv7"
29
+ )
30
+
31
+ interface.launch()