asdrty123 commited on
Commit
49ff70f
·
verified ·
1 Parent(s): 4caa500

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -25
app.py CHANGED
@@ -62,12 +62,13 @@ for f in all_files:
62
  hf_models[model_name].append(filename)
63
 
64
  # ---- Merge / display ----
65
- available_models = sorted(set(local_models) | set(hf_models.keys()))
66
 
67
  print("Local models:", local_models)
68
  print("HF models:", list(hf_models.keys()))
69
- print("Available models (combined):", available_models)
70
 
 
71
 
72
 
73
  # Example: load a specific model (like your hubert loader)
@@ -88,34 +89,49 @@ def load_model(model_name):
88
 
89
 
90
 
91
- def model_data(model_name, use_hf=False, repo_id="simpsonsaiorg/stream-models"):
92
  """
93
- Load model data either from local weights folder or from HuggingFace Hub.
94
-
95
- Args:
96
- model_name (str): name of the model (e.g. "homer", "bart")
97
- use_hf (bool): whether to load from HuggingFace instead of local
98
- repo_id (str): HuggingFace repo id
99
-
100
- Returns:
101
- tgt_sr, net_g, vc, version, index_file, if_f0
102
  """
103
- # -----------------------
104
- # 1. Locate .pth file
105
- # -----------------------
106
  if not use_hf:
107
- # Local
108
- model_path = os.path.join(model_root, model_name)
109
- pth_files = [os.path.join(model_path, f) for f in os.listdir(model_path) if f.endswith(".pth")]
110
- index_files = [os.path.join(model_path, f) for f in os.listdir(model_path) if f.endswith(".index")]
 
 
 
 
 
 
 
 
 
 
 
111
  else:
112
- # HuggingFace
113
- pth_files = [hf_hub_download(repo_id=repo_id, filename=f"{model_name}/model.pth")]
114
- try:
115
- index_files = [hf_hub_download(repo_id=repo_id, filename=f"{model_name}/model.index")]
116
- except Exception:
117
- index_files = []
 
 
 
 
 
 
 
 
 
 
 
 
118
 
 
 
119
  if len(pth_files) == 0:
120
  raise ValueError(f"No .pth file found for model {model_name}")
121
  pth_path = pth_files[0]
 
62
  hf_models[model_name].append(filename)
63
 
64
  # ---- Merge / display ----
65
+ av_models = sorted(set(local_models) | set(hf_models.keys()))
66
 
67
  print("Local models:", local_models)
68
  print("HF models:", list(hf_models.keys()))
69
+ print("Available models (combined):", av_models)
70
 
71
+ models = local_models
72
 
73
 
74
  # Example: load a specific model (like your hubert loader)
 
89
 
90
 
91
 
92
+ def model_data(model_name, model_root="weights", repo_id="simpsonsaiorg/stream-models", use_hf=False):
93
  """
94
+ Load a model either from local disk or HuggingFace repo.
 
 
 
 
 
 
 
 
95
  """
96
+
 
 
97
  if not use_hf:
98
+ # --- Local load ---
99
+ pth_files = [
100
+ os.path.join(model_root, model_name, f)
101
+ for f in os.listdir(os.path.join(model_root, model_name))
102
+ if f.endswith(".pth")
103
+ ]
104
+ if len(pth_files) == 0:
105
+ raise ValueError(f"No .pth file found in {model_root}/{model_name}")
106
+ pth_path = pth_files[0]
107
+
108
+ index_files = [
109
+ os.path.join(model_root, model_name, f)
110
+ for f in os.listdir(os.path.join(model_root, model_name))
111
+ if f.endswith(".index")
112
+ ]
113
  else:
114
+ # --- HuggingFace load ---
115
+ # List all files in the repo first
116
+ all_files = api.list_repo_files(repo_id)
117
+ model_files = [f for f in all_files if f.startswith(f"weights/{model_name}/")]
118
+
119
+ # Find .pth file (pick the first one)
120
+ pth_files = [f for f in model_files if f.endswith(".pth")]
121
+ if not pth_files:
122
+ raise ValueError(f"No .pth file found for model {model_name} in repo")
123
+ pth_path = hf_hub_download(repo_id=repo_id, filename=pth_files[0])
124
+
125
+ # Find optional index files (match any pattern like added_IVF*_v2.index)
126
+ index_files = [
127
+ hf_hub_download(repo_id=repo_id, filename=f)
128
+ for f in model_files
129
+ if f.endswith(".index") and "added_IVF" in f
130
+ ]
131
+
132
 
133
+ print(f"Loading {pth_path}")
134
+
135
  if len(pth_files) == 0:
136
  raise ValueError(f"No .pth file found for model {model_name}")
137
  pth_path = pth_files[0]