Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,27 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
|
|
|
| 3 |
|
| 4 |
-
# تحميل
|
| 5 |
tokenizer = AutoTokenizer.from_pretrained("faisalq/SaudiBERT")
|
| 6 |
-
|
| 7 |
|
| 8 |
-
# تحميل نموذج
|
| 9 |
-
|
| 10 |
-
processor = Wav2Vec2Processor.from_pretrained("facebook/fastspeech2-en-ljspeech")
|
| 11 |
|
| 12 |
# دالة لتحليل النص باستخدام SaudiBERT
|
| 13 |
-
def
|
| 14 |
inputs = tokenizer(text, return_tensors="pt")
|
| 15 |
-
outputs =
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
-
# دالة
|
| 19 |
-
def
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
speech = model.generate(**inputs)
|
| 24 |
-
return processor.decode(speech[0])
|
| 25 |
|
| 26 |
# واجهة Gradio
|
| 27 |
-
iface = gr.Interface(fn=
|
| 28 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from espnet2.bin.tts_inference import Text2Speech
|
| 3 |
+
from transformers import AutoTokenizer, AutoModel
|
| 4 |
|
| 5 |
+
# تحميل SaudiBERT لتحليل النص
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained("faisalq/SaudiBERT")
|
| 7 |
+
model = AutoModel.from_pretrained("faisalq/SaudiBERT")
|
| 8 |
|
| 9 |
+
# تحميل نموذج FastSpeech2
|
| 10 |
+
tts = Text2Speech.from_pretrained("kan-bayashi/fastspeech2")
|
|
|
|
| 11 |
|
| 12 |
# دالة لتحليل النص باستخدام SaudiBERT
|
| 13 |
+
def analyze_text(text):
|
| 14 |
inputs = tokenizer(text, return_tensors="pt")
|
| 15 |
+
outputs = model(**inputs)
|
| 16 |
+
# يمكنك تعديل النص هنا استنادًا إلى التحليل
|
| 17 |
+
return text # إعادة النص للتحويل بعد التحليل
|
| 18 |
|
| 19 |
+
# دالة لتحويل النص إلى كلام
|
| 20 |
+
def tts_najdi(text):
|
| 21 |
+
processed_text = analyze_text(text)
|
| 22 |
+
speech = tts(processed_text)
|
| 23 |
+
return speech['wav']
|
|
|
|
|
|
|
| 24 |
|
| 25 |
# واجهة Gradio
|
| 26 |
+
iface = gr.Interface(fn=tts_najdi, inputs="text", outputs="audio", title="FastSpeech2 Najdi TTS Model with SaudiBERT")
|
| 27 |
iface.launch()
|