Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import gradio as gr
|
3 |
+
import torchaudio
|
4 |
+
from transformers import VitsModel, VitsTokenizer
|
5 |
+
from numToAce import convert_number_to_aceh
|
6 |
+
|
7 |
+
model_id = "facebook/mms-tts-ace"
|
8 |
+
tokenizer = VitsTokenizer.from_pretrained(model_id)
|
9 |
+
model = VitsModel.from_pretrained(model_id)
|
10 |
+
|
11 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
12 |
+
model.to(device)
|
13 |
+
|
14 |
+
def tts_aceh(text):
|
15 |
+
text = convert_number_to_aceh(text)
|
16 |
+
inputs = tokenizer(text, return_tensors="pt").to(device)
|
17 |
+
|
18 |
+
with torch.no_grad():
|
19 |
+
outputs = model(**inputs)
|
20 |
+
|
21 |
+
waveform = outputs.waveform.squeeze().cpu()
|
22 |
+
sample_rate = model.config.sampling_rate
|
23 |
+
return (sample_rate, waveform)
|
24 |
+
|
25 |
+
demo = gr.Interface(
|
26 |
+
fn=tts_aceh,
|
27 |
+
inputs=gr.Textbox(label="Nhập văn bản tiếng Aceh"),
|
28 |
+
outputs=gr.Audio(label="Giọng đọc tiếng Aceh"),
|
29 |
+
title="TTS tiếng Aceh (MMS-VITS)",
|
30 |
+
description="Mô hình VITS từ Meta AI, hoạt động trực tiếp với Gradio"
|
31 |
+
)
|
32 |
+
|
33 |
+
if __name__ == "__main__":
|
34 |
+
demo.launch()
|