Inial commited on
Commit
3fe8773
·
verified ·
1 Parent(s): 3145aa9

Create app py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor
3
+ import torch
4
+
5
+ device = "cuda" if torch.cuda.is_available() else "cpu"
6
+ model_id = "facebook/mms-tts-ava"
7
+
8
+ processor = AutoProcessor.from_pretrained(model_id)
9
+ model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id).to(device)
10
+
11
+ def tts_fn(text):
12
+ inputs = processor(text=text, return_tensors="pt").to(device)
13
+ with torch.no_grad():
14
+ waveform = model.generate(**inputs)
15
+ audio = waveform.squeeze().cpu().numpy()
16
+ return (16000, audio)
17
+
18
+ gr.Interface(fn=tts_fn,
19
+ inputs=gr.Textbox(label="Nhập văn bản bằng tiếng Avar"),
20
+ outputs=gr.Audio(label="Âm thanh (16kHz)"),
21
+ title="Avar TTS - facebook/mms-tts-ava",
22
+ description="Dùng thử TTS tiếng Avar bằng mô hình MMS từ Meta (facebook/mms-tts-ava). Chỉ để thử nghiệm, không thương mại.").launch()