Spaces:
Sleeping
Sleeping
Commit ·
66a8297
1
Parent(s): 5b42de2
feat: integrate AFx-Rep model downloading using huggingface_hub
Browse files- app.py +17 -0
- st_ito/utils.py +22 -11
app.py
CHANGED
|
@@ -6,6 +6,8 @@ import torch
|
|
| 6 |
from torch import Tensor
|
| 7 |
import math
|
| 8 |
import yaml
|
|
|
|
|
|
|
| 9 |
import json
|
| 10 |
import pyloudnorm as pyln
|
| 11 |
from hydra.utils import instantiate
|
|
@@ -34,6 +36,21 @@ from st_ito.utils import (
|
|
| 34 |
load_mir_feature_extractor,
|
| 35 |
)
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
title_md = "# Vocal Effects Style Transfer Demo"
|
| 39 |
description_md = """
|
|
|
|
| 6 |
from torch import Tensor
|
| 7 |
import math
|
| 8 |
import yaml
|
| 9 |
+
import os
|
| 10 |
+
from huggingface_hub import hf_hub_download
|
| 11 |
import json
|
| 12 |
import pyloudnorm as pyln
|
| 13 |
from hydra.utils import instantiate
|
|
|
|
| 36 |
load_mir_feature_extractor,
|
| 37 |
)
|
| 38 |
|
| 39 |
+
# Download AFx-Rep model and config files
|
| 40 |
+
os.makedirs("tmp", exist_ok=True)
|
| 41 |
+
ckpt_path = hf_hub_download(
|
| 42 |
+
repo_id="csteinmetz1/afx-rep",
|
| 43 |
+
filename="afx-rep.ckpt",
|
| 44 |
+
local_dir="tmp",
|
| 45 |
+
local_files_only=False,
|
| 46 |
+
)
|
| 47 |
+
config_path = hf_hub_download(
|
| 48 |
+
repo_id="csteinmetz1/afx-rep",
|
| 49 |
+
filename="config.yaml",
|
| 50 |
+
local_dir="tmp",
|
| 51 |
+
local_files_only=False,
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
|
| 55 |
title_md = "# Vocal Effects Style Transfer Demo"
|
| 56 |
description_md = """
|
st_ito/utils.py
CHANGED
|
@@ -5,6 +5,7 @@ import torchaudio
|
|
| 5 |
import pyloudnorm as pyln
|
| 6 |
from typing import Optional
|
| 7 |
from importlib import import_module
|
|
|
|
| 8 |
|
| 9 |
from modules.encoder import (
|
| 10 |
StatisticReduction,
|
|
@@ -112,18 +113,28 @@ def get_param_embeds(
|
|
| 112 |
def load_param_model(ckpt_path: Optional[str] = None):
|
| 113 |
|
| 114 |
if ckpt_path is None: # look in tmp direcory
|
| 115 |
-
ckpt_path = os.path.join(os.getcwd(), "tmp", "afx-rep.ckpt")
|
| 116 |
os.makedirs("tmp", exist_ok=True)
|
| 117 |
-
if not os.path.isfile(ckpt_path):
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
with open(config_path) as f:
|
| 129 |
config = yaml.safe_load(f)
|
|
|
|
| 5 |
import pyloudnorm as pyln
|
| 6 |
from typing import Optional
|
| 7 |
from importlib import import_module
|
| 8 |
+
from huggingface_hub import hf_hub_download
|
| 9 |
|
| 10 |
from modules.encoder import (
|
| 11 |
StatisticReduction,
|
|
|
|
| 113 |
def load_param_model(ckpt_path: Optional[str] = None):
|
| 114 |
|
| 115 |
if ckpt_path is None: # look in tmp direcory
|
| 116 |
+
# ckpt_path = os.path.join(os.getcwd(), "tmp", "afx-rep.ckpt")
|
| 117 |
os.makedirs("tmp", exist_ok=True)
|
| 118 |
+
# if not os.path.isfile(ckpt_path):
|
| 119 |
+
# download from huggingfacehub
|
| 120 |
+
# os.system(
|
| 121 |
+
# "wget -O tmp/afx-rep.ckpt https://huggingface.co/csteinmetz1/afx-rep/resolve/main/afx-rep.ckpt"
|
| 122 |
+
# )
|
| 123 |
+
# os.system(
|
| 124 |
+
# "wget -O tmp/config.yaml https://huggingface.co/csteinmetz1/afx-rep/resolve/main/config.yaml"
|
| 125 |
+
# )
|
| 126 |
+
ckpt_path = hf_hub_download(
|
| 127 |
+
repo_id="csteinmetz1/afx-rep",
|
| 128 |
+
filename="afx-rep.ckpt",
|
| 129 |
+
local_dir="tmp",
|
| 130 |
+
)
|
| 131 |
+
config_path = hf_hub_download(
|
| 132 |
+
repo_id="csteinmetz1/afx-rep",
|
| 133 |
+
filename="config.yaml",
|
| 134 |
+
local_dir="tmp",
|
| 135 |
+
)
|
| 136 |
+
else:
|
| 137 |
+
config_path = os.path.join(os.path.dirname(ckpt_path), "config.yaml")
|
| 138 |
|
| 139 |
with open(config_path) as f:
|
| 140 |
config = yaml.safe_load(f)
|