Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,26 @@
|
|
| 1 |
import torch
|
| 2 |
-
from transformers import
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 11 |
-
model.to(device)
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
def
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
output = model.generate(**inputs)
|
| 18 |
-
audio = output.cpu().numpy()[0]
|
| 19 |
-
return (16000, audio) # sample rate, waveform
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
-
fn=
|
| 24 |
-
inputs=gr.Textbox(label="Nhập văn bản Yakut"),
|
| 25 |
-
outputs=gr.Audio(label="
|
| 26 |
-
title="Yakut
|
| 27 |
-
description="
|
| 28 |
)
|
| 29 |
|
| 30 |
if __name__ == "__main__":
|
| 31 |
-
|
|
|
|
| 1 |
import torch
|
| 2 |
+
from transformers import pipeline
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
# Tự động dùng GPU nếu có
|
| 6 |
+
device = 0 if torch.cuda.is_available() else -1
|
| 7 |
|
| 8 |
+
# Tải pipeline TTS cho tiếng Yakut (mã ngôn ngữ: sah)
|
| 9 |
+
yakut_tts = pipeline("text-to-speech", model="facebook/mms-tts-sah", device=device)
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# Hàm chuyển văn bản sang giọng nói
|
| 12 |
+
def yakut_voice(text):
|
| 13 |
+
result = yakut_tts(text)
|
| 14 |
+
return result["audio"]
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
# Giao diện Gradio
|
| 17 |
+
app = gr.Interface(
|
| 18 |
+
fn=yakut_voice,
|
| 19 |
+
inputs=gr.Textbox(label="Nhập văn bản tiếng Yakut"),
|
| 20 |
+
outputs=gr.Audio(label="Giọng nói Yakut"),
|
| 21 |
+
title="Yakut Text-to-Speech",
|
| 22 |
+
description="Chuyển văn bản Yakut (sah) thành giọng nói bằng mô hình Facebook MMS"
|
| 23 |
)
|
| 24 |
|
| 25 |
if __name__ == "__main__":
|
| 26 |
+
app.launch()
|