jellecali8 commited on
Commit
0d93147
·
verified ·
1 Parent(s): b20a4f8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor
3
+ import torch
4
+ import soundfile as sf
5
+ import tempfile
6
+
7
+ model_id = "jellecali8/somali_tts_model"
8
+
9
+ processor = AutoProcessor.from_pretrained(model_id)
10
+ model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id)
11
+
12
+ def tts(text):
13
+ inputs = processor(text, return_tensors="pt")
14
+ with torch.no_grad():
15
+ outputs = model.generate(**inputs)
16
+ audio = outputs[0].cpu().numpy()
17
+
18
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as f:
19
+ sf.write(f.name, audio, samplerate=16000)
20
+ return f.name
21
+
22
+ iface = gr.Interface(
23
+ fn=tts,
24
+ inputs=gr.Textbox(lines=2, placeholder="Ku qor qoraalka Somali halkan...", label="Qoraalka Somali"),
25
+ outputs=gr.Audio(label="Codka la soo saaray"),
26
+ title="Somali TTS Demo",
27
+ description="Qoraal ku qor af-Soomaali kadib dhageyso codka."
28
+ )
29
+
30
+ iface.launch()