Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import AutoProcessor, VitsModel
|
| 4 |
+
|
| 5 |
+
model_id = "facebook/mms-tts-nko"
|
| 6 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 7 |
+
|
| 8 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
| 9 |
+
model = VitsModel.from_pretrained(model_id).to(device)
|
| 10 |
+
|
| 11 |
+
def tts_nko(text):
|
| 12 |
+
try:
|
| 13 |
+
inputs = processor(text=text, return_tensors="pt").to(device)
|
| 14 |
+
with torch.no_grad():
|
| 15 |
+
output = model(**inputs)
|
| 16 |
+
waveform = output.waveform[0].cpu().numpy()
|
| 17 |
+
return f"✅ Giọng N’Ko (nko)", (waveform, 16000)
|
| 18 |
+
except Exception as e:
|
| 19 |
+
return f"❌ Lỗi: {str(e)}", None
|
| 20 |
+
|
| 21 |
+
with gr.Blocks() as demo:
|
| 22 |
+
gr.Markdown("# 🔊 N’Ko TTS (ߒߞߏ /nko/)")
|
| 23 |
+
text_input = gr.Textbox(label="Nhập văn bản N’Ko (ߒߞߏ...)")
|
| 24 |
+
output_text = gr.Textbox(label="Trạng thái")
|
| 25 |
+
output_audio = gr.Audio(label="Phát âm", type="numpy")
|
| 26 |
+
btn = gr.Button("Phát")
|
| 27 |
+
|
| 28 |
+
btn.click(fn=tts_nko, inputs=[text_input], outputs=[output_text, output_audio])
|
| 29 |
+
|
| 30 |
+
demo.launch()
|