ollui commited on
Commit
e2270b8
·
verified ·
1 Parent(s): 286632f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoProcessor, BarkModel
3
+ import torch
4
+ import uuid
5
+ import os
6
+ from datasets import load_dataset
7
+ from scipy.io.wavfile import write
8
+
9
+ from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
10
+
11
+ model_id = "facebook/mms-tts-bo"
12
+ processor = AutoProcessor.from_pretrained(model_id)
13
+ model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id)
14
+
15
+ device = "cuda" if torch.cuda.is_available() else "cpu"
16
+ model.to(device)
17
+
18
+ def tts_tibetan(text):
19
+ if not text.strip():
20
+ return "Vui lòng nhập văn bản."
21
+
22
+ inputs = processor(text=text, return_tensors="pt").to(device)
23
+ with torch.no_grad():
24
+ generated = model.generate(**inputs)
25
+
26
+ speech = processor.decode(generated[0])
27
+ output_path = f"/tmp/{uuid.uuid4().hex}.wav"
28
+ processor.save_wav(speech, output_path)
29
+
30
+ return output_path
31
+
32
+ iface = gr.Interface(
33
+ fn=tts_tibetan,
34
+ inputs=gr.Textbox(label="Nhập văn bản tiếng Tây Tạng (Unicode)"),
35
+ outputs=gr.Audio(type="filepath", label="Giọng đọc Tây Tạng (MMS)"),
36
+ title="TTS tiếng Tây Tạng bằng Facebook MMS",
37
+ description="Sử dụng mô hình MMS để tạo giọng đọc tiếng Tây Tạng"
38
+ )
39
+
40
+ iface.launch()