HusseinBashir commited on
Commit
a50ffbb
·
verified ·
1 Parent(s): 64e49f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -8
app.py CHANGED
@@ -5,14 +5,13 @@ import scipy.io.wavfile
5
  from transformers import VitsModel, AutoTokenizer
6
  import re
7
 
8
- # Load model
9
  model = VitsModel.from_pretrained("Somali-tts/somali_tts_model")
10
  tokenizer = AutoTokenizer.from_pretrained("saleolow/somali-mms-tts")
11
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
12
  model.to(device)
13
  model.eval()
14
 
15
- # Number normalization
16
  number_words = {
17
  0: "eber", 1: "koow", 2: "labo", 3: "seddex", 4: "afar", 5: "shan",
18
  6: "lix", 7: "todobo", 8: "sideed", 9: "sagaal", 10: "toban",
@@ -76,7 +75,6 @@ def normalize_text(text):
76
  text = text.replace("ZamZam", "SamSam")
77
  return text
78
 
79
- # TTS function
80
  def tts(text):
81
  text = normalize_text(text)
82
  inputs = tokenizer(text, return_tensors="pt").to(device)
@@ -84,13 +82,13 @@ def tts(text):
84
  waveform = model(**inputs).waveform.squeeze().cpu().numpy()
85
  filename = "output.wav"
86
  scipy.io.wavfile.write(filename, rate=model.config.sampling_rate, data=(waveform * 32767).astype(np.int16))
87
- return f"https://HusseinBashir--Somali_tts.hf.space/file={filename}"
88
 
89
- # Interface + Launch
90
  gr.Interface(
91
  fn=tts,
92
  inputs=gr.Textbox(label="Geli qoraal Soomaali ah"),
93
- outputs=gr.Audio(type="filepath", label="Codka TTS"),
94
- title="Somali Text-to-Speech",
95
- description="Ku qor qoraal Soomaali ah si aad u maqasho codka."
96
  ).launch()
 
 
5
  from transformers import VitsModel, AutoTokenizer
6
  import re
7
 
8
+ # Load fine-tuned model from Hugging Face Hub or local path
9
  model = VitsModel.from_pretrained("Somali-tts/somali_tts_model")
10
  tokenizer = AutoTokenizer.from_pretrained("saleolow/somali-mms-tts")
11
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
12
  model.to(device)
13
  model.eval()
14
 
 
15
  number_words = {
16
  0: "eber", 1: "koow", 2: "labo", 3: "seddex", 4: "afar", 5: "shan",
17
  6: "lix", 7: "todobo", 8: "sideed", 9: "sagaal", 10: "toban",
 
75
  text = text.replace("ZamZam", "SamSam")
76
  return text
77
 
 
78
  def tts(text):
79
  text = normalize_text(text)
80
  inputs = tokenizer(text, return_tensors="pt").to(device)
 
82
  waveform = model(**inputs).waveform.squeeze().cpu().numpy()
83
  filename = "output.wav"
84
  scipy.io.wavfile.write(filename, rate=model.config.sampling_rate, data=(waveform * 32767).astype(np.int16))
85
+ return filename
86
 
 
87
  gr.Interface(
88
  fn=tts,
89
  inputs=gr.Textbox(label="Geli qoraal Soomaali ah"),
90
+ outputs=gr.Audio(label="Codka TTS"),
91
+ title="Somali TTS",
92
+ description="Ku qor qoraal Soomaaliyeed si aad u maqasho cod dabiici ah.",
93
  ).launch()
94
+