ollui commited on
Commit
6cb16a1
·
verified ·
1 Parent(s): b959531

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -22
app.py CHANGED
@@ -1,31 +1,26 @@
1
  import torch
2
- from transformers import VitsForConditionalGeneration, VitsTokenizer
3
  import gradio as gr
4
 
5
- # Load model Yakut VITS (em thay model_id đúng nếu có)
6
- model_id = "facebook/mms-tts-sah" # Yakut = sah
7
 
8
- tokenizer = VitsTokenizer.from_pretrained(model_id)
9
- model = VitsForConditionalGeneration.from_pretrained(model_id)
10
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
11
- model.to(device)
12
 
13
- # Hàm chuyển văn bản Yakut thành audio
14
- def yakut_tts(text):
15
- inputs = tokenizer(text, return_tensors="pt").to(device)
16
- with torch.no_grad():
17
- output = model.generate(**inputs)
18
- audio = output.cpu().numpy()[0]
19
- return (16000, audio) # sample rate, waveform
20
 
21
- # Giao diện Gradio
22
- interface = gr.Interface(
23
- fn=yakut_tts,
24
- inputs=gr.Textbox(label="Nhập văn bản Yakut"),
25
- outputs=gr.Audio(label="Phát âm Yakut", type="numpy"),
26
- title="Yakut TTS App",
27
- description="Ứng dụng chuyển văn bản tiếng Yakut sang giọng nói bằng VITS"
28
  )
29
 
30
  if __name__ == "__main__":
31
- interface.launch()
 
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()