Spaces:
Running
Running
fabiogra
commited on
Commit
β’
4c92361
1
Parent(s):
1cea6a5
fix: st.audio in separate.py and prepare_samples script
Browse files- app/pages/Separate.py +2 -5
- scripts/inference.py +19 -11
- scripts/prepare_samples.sh +7 -5
- scripts/sample_songs.json +1 -6
- scripts/separate_songs.json +6 -6
app/pages/Separate.py
CHANGED
@@ -81,7 +81,7 @@ def show_results(model_name: str, dir_name_output: str, file_sources: List):
|
|
81 |
)
|
82 |
with cols[1]:
|
83 |
st_local_audio(pathname, key=f"output_{file}_{dir_name_output}")
|
84 |
-
log.info(f"Displaying results for {dir_name_output}")
|
85 |
|
86 |
|
87 |
def body():
|
@@ -140,10 +140,7 @@ def body():
|
|
140 |
help="Supported formats: mp3, wav, ogg, flac.",
|
141 |
)
|
142 |
if uploaded_file is not None:
|
143 |
-
|
144 |
-
f.write(uploaded_file.getbuffer())
|
145 |
-
filename = uploaded_file.name
|
146 |
-
st_local_audio(in_path / filename, key="input_upload_file")
|
147 |
|
148 |
elif option == "From URL":
|
149 |
url = st.text_input(
|
|
|
81 |
)
|
82 |
with cols[1]:
|
83 |
st_local_audio(pathname, key=f"output_{file}_{dir_name_output}")
|
84 |
+
log.info(f"Displaying results for {dir_name_output} - {model_name}")
|
85 |
|
86 |
|
87 |
def body():
|
|
|
140 |
help="Supported formats: mp3, wav, ogg, flac.",
|
141 |
)
|
142 |
if uploaded_file is not None:
|
143 |
+
st.audio(uploaded_file)
|
|
|
|
|
|
|
144 |
|
145 |
elif option == "From URL":
|
146 |
url = st.text_input(
|
scripts/inference.py
CHANGED
@@ -16,20 +16,20 @@ def main():
|
|
16 |
p.add_argument("--pretrained_model", "-P", type=str, default="baseline.pth")
|
17 |
p.add_argument("--input", "-i", required=True)
|
18 |
p.add_argument("--output_dir", "-o", type=str, default="")
|
19 |
-
p.add_argument("--
|
20 |
args = p.parse_args()
|
21 |
-
|
22 |
input_file = args.input
|
23 |
-
|
24 |
model, device = load_model(pretrained_model=args.pretrained_model)
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
for stem, model_name in [("vocals", "htdemucs"), (None, "htdemucs"), (None, "htdemucs_6s")]:
|
34 |
separator(
|
35 |
tracks=[Path(input_file)],
|
@@ -45,6 +45,14 @@ def main():
|
|
45 |
mp3_bitrate=320,
|
46 |
verbose=False,
|
47 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
|
50 |
if __name__ == "__main__":
|
|
|
16 |
p.add_argument("--pretrained_model", "-P", type=str, default="baseline.pth")
|
17 |
p.add_argument("--input", "-i", required=True)
|
18 |
p.add_argument("--output_dir", "-o", type=str, default="")
|
19 |
+
p.add_argument("--full_mode", "-n", default=False)
|
20 |
args = p.parse_args()
|
21 |
+
print(args)
|
22 |
input_file = args.input
|
23 |
+
full_mode = bool(args.full_mode)
|
24 |
model, device = load_model(pretrained_model=args.pretrained_model)
|
25 |
+
|
26 |
+
if full_mode:
|
27 |
+
separate(
|
28 |
+
input=input_file,
|
29 |
+
model=model,
|
30 |
+
device=device,
|
31 |
+
output_dir=args.output_dir,
|
32 |
+
)
|
33 |
for stem, model_name in [("vocals", "htdemucs"), (None, "htdemucs"), (None, "htdemucs_6s")]:
|
34 |
separator(
|
35 |
tracks=[Path(input_file)],
|
|
|
45 |
mp3_bitrate=320,
|
46 |
verbose=False,
|
47 |
)
|
48 |
+
else:
|
49 |
+
separate(
|
50 |
+
input=input_file,
|
51 |
+
model=model,
|
52 |
+
device=device,
|
53 |
+
output_dir=args.output_dir,
|
54 |
+
only_no_vocals=True,
|
55 |
+
)
|
56 |
|
57 |
|
58 |
if __name__ == "__main__":
|
scripts/prepare_samples.sh
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
#!/bin/bash
|
2 |
-
|
3 |
# Read the secret into a variable
|
4 |
export PREPARE_SAMPLES=$(cat /run/secrets/PREPARE_SAMPLES)
|
5 |
|
@@ -33,13 +33,15 @@ json_separate=$(cat separate_songs.json)
|
|
33 |
|
34 |
# Iterate through keys and values
|
35 |
for name in $(echo "${json_separate}" | jq -r 'keys[]'); do
|
36 |
-
url=$(echo "${json_separate}" | jq -r --arg name "${name}" '.[$name]')
|
37 |
-
echo "
|
|
|
|
|
38 |
|
39 |
# Download with pytube
|
40 |
-
yt-dlp ${url} -o "/tmp/${name}" --format "bestaudio/best" --download-sections "
|
41 |
|
42 |
# Run inference
|
43 |
-
python inference.py --input /tmp/${name} --output /tmp --
|
44 |
echo "Done separating ${name}"
|
45 |
done
|
|
|
1 |
#!/bin/bash
|
2 |
+
echo "Starting prepare_samples.sh..."
|
3 |
# Read the secret into a variable
|
4 |
export PREPARE_SAMPLES=$(cat /run/secrets/PREPARE_SAMPLES)
|
5 |
|
|
|
33 |
|
34 |
# Iterate through keys and values
|
35 |
for name in $(echo "${json_separate}" | jq -r 'keys[]'); do
|
36 |
+
url=$(echo "${json_separate}" | jq -r --arg name "${name}" '.[$name][0]')
|
37 |
+
start_time=$(echo "${json_separate}" | jq -r --arg name "${name}" '.[$name][1]')
|
38 |
+
end_time=$(expr $start_time + 20)
|
39 |
+
echo "Separating ${name} from ${url} with start_time ${start_time} sec"
|
40 |
|
41 |
# Download with pytube
|
42 |
+
yt-dlp ${url} -o "/tmp/${name}" --format "bestaudio/best" --download-sections "*${start_time}-${end_time}"
|
43 |
|
44 |
# Run inference
|
45 |
+
python inference.py --input /tmp/${name} --output /tmp --full_mode 1
|
46 |
echo "Done separating ${name}"
|
47 |
done
|
scripts/sample_songs.json
CHANGED
@@ -1,8 +1,3 @@
|
|
1 |
{
|
2 |
-
"dancing_queen": "https://www.youtube.com/watch?v=3qiMJt-JBb4"
|
3 |
-
"bohemian_rhapsody": "https://www.youtube.com/watch?v=yk3prd8GER4",
|
4 |
-
"i_want_it_that_way": "https://www.youtube.com/watch?v=qjlVAsvQLM8",
|
5 |
-
"let_it_be": "https://www.youtube.com/watch?v=FIV73iG_e5I",
|
6 |
-
"viva_la_vida": "https://www.youtube.com/watch?v=a1EYnngNHIA",
|
7 |
-
"zombie": "https://www.youtube.com/watch?v=8sM-rm4lFZg"
|
8 |
}
|
|
|
1 |
{
|
2 |
+
"dancing_queen": "https://www.youtube.com/watch?v=3qiMJt-JBb4"
|
|
|
|
|
|
|
|
|
|
|
3 |
}
|
scripts/separate_songs.json
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
{
|
2 |
-
"ABBA_-_Dancing_Queen": "https://www.youtube.com/watch?v=3qiMJt-JBb4",
|
3 |
-
"Queen_β_Bohemian_Rhapsody": "https://www.youtube.com/watch?v=yk3prd8GER4",
|
4 |
-
"Backstreet_Boys_-_I_Want_It_That_Way": "https://www.youtube.com/watch?v=qjlVAsvQLM8",
|
5 |
-
"The_Beatles_-_Let_It_Be": "https://www.youtube.com/watch?v=FIV73iG_e5I",
|
6 |
-
"Coldplay_-_Viva_La_Vida": "https://www.youtube.com/watch?v=a1EYnngNHIA",
|
7 |
-
"The_Cranberries_-_Zombie": "https://www.youtube.com/watch?v=8sM-rm4lFZg"
|
8 |
}
|
|
|
1 |
{
|
2 |
+
"ABBA_-_Dancing_Queen": ["https://www.youtube.com/watch?v=3qiMJt-JBb4",85],
|
3 |
+
"Queen_β_Bohemian_Rhapsody": ["https://www.youtube.com/watch?v=yk3prd8GER4", 86],
|
4 |
+
"Backstreet_Boys_-_I_Want_It_That_Way": ["https://www.youtube.com/watch?v=qjlVAsvQLM8", 43],
|
5 |
+
"The_Beatles_-_Let_It_Be": ["https://www.youtube.com/watch?v=FIV73iG_e5I", 82],
|
6 |
+
"Coldplay_-_Viva_La_Vida": ["https://www.youtube.com/watch?v=a1EYnngNHIA", 7],
|
7 |
+
"The_Cranberries_-_Zombie": ["https://www.youtube.com/watch?v=8sM-rm4lFZg", 82],
|
8 |
}
|