m6011 commited on
Commit
739b974
1 Parent(s): bfff99a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -17
app.py CHANGED
@@ -1,28 +1,27 @@
1
  import gradio as gr
2
- from transformers import FastSpeechForConditionalGeneration, Wav2Vec2Processor, AutoTokenizer, AutoModel
 
3
 
4
- # تحميل نموذج SaudiBERT لتحليل النص
5
  tokenizer = AutoTokenizer.from_pretrained("faisalq/SaudiBERT")
6
- bert_model = AutoModel.from_pretrained("faisalq/SaudiBERT")
7
 
8
- # تحميل نموذج FastSpeech
9
- model = FastSpeechForConditionalGeneration.from_pretrained("facebook/fastspeech2-en-ljspeech")
10
- processor = Wav2Vec2Processor.from_pretrained("facebook/fastspeech2-en-ljspeech")
11
 
12
  # دالة لتحليل النص باستخدام SaudiBERT
13
- def analyze_text_with_bert(text):
14
  inputs = tokenizer(text, return_tensors="pt")
15
- outputs = bert_model(**inputs)
16
- return outputs
 
17
 
18
- # دالة تحويل النص إلى كلام
19
- def tts(text):
20
- # تحليل النص قبل التحويل باستخدام SaudiBERT
21
- analyzed_text = analyze_text_with_bert(text)
22
- inputs = processor(text, return_tensors="pt")
23
- speech = model.generate(**inputs)
24
- return processor.decode(speech[0])
25
 
26
  # واجهة Gradio
27
- iface = gr.Interface(fn=tts, inputs="text", outputs="audio", title="Najdi TTS with SaudiBERT")
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()