mhrahmani commited on
Commit
e4b3e78
1 Parent(s): d60ac5e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -9,23 +9,27 @@ MODEL_INFO = [
9
  ["vits-espeak-57000", "checkpoint_57000.pth", "config.json", "mhrahmani/persian-tts-vits-0"],
10
  ]
11
 
12
- # Extract model names from MODEL_INFO
13
- MODEL_NAMES = [info[0] for info in MODEL_INFO]
 
 
 
 
 
 
14
 
15
  MAX_TXT_LEN = 400
16
  TOKEN = os.getenv('HUGGING_FACE_HUB_TOKEN')
17
 
18
- # Dictionary to keep synthesizers
19
- synthesizers = {}
20
-
21
- # Download files and create synthesizers
22
  for model_name, model_file, config_file, repo_name in MODEL_INFO:
 
23
  print(f"|> Downloading: {model_name}")
 
 
 
 
24
 
25
- model_file_path = hf_hub_download(repo_id=repo_name, filename=model_file, use_auth_token=TOKEN)
26
- config_file_path = hf_hub_download(repo_id=repo_name, filename=config_file, use_auth_token=TOKEN)
27
-
28
- synthesizers[model_name] = Synthesizer(model_file_path, config_file_path)
29
 
30
  def synthesize(text: str, model_name: str) -> str:
31
  """Synthesize speech using the selected model."""
@@ -33,10 +37,10 @@ def synthesize(text: str, model_name: str) -> str:
33
  text = text[:MAX_TXT_LEN]
34
  print(f"Input text was cut off as it exceeded the {MAX_TXT_LEN} character limit.")
35
 
36
- synthesizer = synthesizers[model_name]
37
  if synthesizer is None:
38
  raise NameError("Model not found")
39
-
40
  wavs = synthesizer.tts(text)
41
 
42
  with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
 
9
  ["vits-espeak-57000", "checkpoint_57000.pth", "config.json", "mhrahmani/persian-tts-vits-0"],
10
  ]
11
 
12
+ # # Extract model names from MODEL_INFO
13
+ # MODEL_NAMES = [info[0] for info in MODEL_INFO]
14
+
15
+ MODEL_NAMES = [
16
+ "vits checkoint 57000",
17
+ # Add other model names similarly...
18
+ ]
19
+
20
 
21
  MAX_TXT_LEN = 400
22
  TOKEN = os.getenv('HUGGING_FACE_HUB_TOKEN')
23
 
24
+ # Download models
 
 
 
25
  for model_name, model_file, config_file, repo_name in MODEL_INFO:
26
+ os.makedirs(model_name, exist_ok=True)
27
  print(f"|> Downloading: {model_name}")
28
+
29
+ # Use hf_hub_download to download models from private Hugging Face repositories
30
+ hf_hub_download(repo_id=repo_name, filename=model_file, cache_dir=model_name, use_auth_token=TOKEN)
31
+ hf_hub_download(repo_id=repo_name, filename=config_file, cache_dir=model_name, use_auth_token=TOKEN)
32
 
 
 
 
 
33
 
34
  def synthesize(text: str, model_name: str) -> str:
35
  """Synthesize speech using the selected model."""
 
37
  text = text[:MAX_TXT_LEN]
38
  print(f"Input text was cut off as it exceeded the {MAX_TXT_LEN} character limit.")
39
 
40
+ synthesizer = Synthesizer(f"{model_name}/{model_file}", f"{model_name}/{config_file}")
41
  if synthesizer is None:
42
  raise NameError("Model not found")
43
+
44
  wavs = synthesizer.tts(text)
45
 
46
  with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp: