import gradio as gr from transformers import FastSpeechForConditionalGeneration, Wav2Vec2Processor, AutoTokenizer, AutoModel # تحميل نموذج SaudiBERT لتحليل النص tokenizer = AutoTokenizer.from_pretrained("faisalq/SaudiBERT") bert_model = AutoModel.from_pretrained("faisalq/SaudiBERT") # تحميل نموذج FastSpeech model = FastSpeechForConditionalGeneration.from_pretrained("facebook/fastspeech2-en-ljspeech") processor = Wav2Vec2Processor.from_pretrained("facebook/fastspeech2-en-ljspeech") # دالة لتحليل النص باستخدام SaudiBERT def analyze_text_with_bert(text): inputs = tokenizer(text, return_tensors="pt") outputs = bert_model(**inputs) return outputs # دالة تحويل النص إلى كلام def tts(text): # تحليل النص قبل التحويل باستخدام SaudiBERT analyzed_text = analyze_text_with_bert(text) inputs = processor(text, return_tensors="pt") speech = model.generate(**inputs) return processor.decode(speech[0]) # واجهة Gradio iface = gr.Interface(fn=tts, inputs="text", outputs="audio", title="Najdi TTS with SaudiBERT") iface.launch()