|
import gradio as gr |
|
from transformers import FastSpeechForConditionalGeneration, Wav2Vec2Processor, AutoTokenizer, AutoModel |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained("faisalq/SaudiBERT") |
|
bert_model = AutoModel.from_pretrained("faisalq/SaudiBERT") |
|
|
|
|
|
model = FastSpeechForConditionalGeneration.from_pretrained("facebook/fastspeech2-en-ljspeech") |
|
processor = Wav2Vec2Processor.from_pretrained("facebook/fastspeech2-en-ljspeech") |
|
|
|
|
|
def analyze_text_with_bert(text): |
|
inputs = tokenizer(text, return_tensors="pt") |
|
outputs = bert_model(**inputs) |
|
return outputs |
|
|
|
|
|
def tts(text): |
|
|
|
analyzed_text = analyze_text_with_bert(text) |
|
inputs = processor(text, return_tensors="pt") |
|
speech = model.generate(**inputs) |
|
return processor.decode(speech[0]) |
|
|
|
|
|
iface = gr.Interface(fn=tts, inputs="text", outputs="audio", title="Najdi TTS with SaudiBERT") |
|
iface.launch() |
|
|