superverynewtts / app.py
ollui's picture
Create app.py
e49f6ab verified
raw
history blame contribute delete
813 Bytes
from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq
import torch
import gradio as gr
import scipy
# Chọn mô hình
model_id = "facebook/mms-tts-bod"
# Load processor và model
processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id)
model.eval()
# Tạo hàm TTS
def tts_fn(text):
inputs = processor(text=text, return_tensors="pt")
with torch.no_grad():
output = model.generate(**inputs)
audio = processor.batch_decode(output, skip_special_tokens=True)[0]
audio_array = processor.decode(output[0], skip_special_tokens=True, return_tensors="np")
return (22050, audio_array)
# Giao diện Gradio
demo = gr.Interface(fn=tts_fn, inputs=gr.Textbox(label="Nhập tiếng Tây Tạng"), outputs="audio")
demo.launch()