Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
return text # إعادة النص للتحويل بعد التحليل
|
17 |
+
|
18 |
+
# دالة لتحويل النص إلى كلام
|
19 |
+
def tts_najdi(text):
|
20 |
+
processed_text = analyze_text(text)
|
21 |
+
speech = tts(processed_text)
|
22 |
+
return speech['wav']
|
23 |
+
|
24 |
+
# واجهة Gradio
|
25 |
+
iface = gr.Interface(fn=tts_najdi, inputs="text", outputs="audio", title="FastSpeech2 Najdi TTS Model with SaudiBERT")
|
26 |
+
iface.launch()
|