Spaces:
Running
Running
fabiogra
commited on
Commit
ยท
8fefa43
1
Parent(s):
17c8c88
fix: upload file, improve style
Browse files- app/pages/Separate.py +17 -12
app/pages/Separate.py
CHANGED
|
@@ -140,7 +140,11 @@ def body():
|
|
| 140 |
help="Supported formats: mp3, wav, ogg, flac.",
|
| 141 |
)
|
| 142 |
if uploaded_file is not None:
|
| 143 |
-
st.audio
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
elif option == "From URL":
|
| 146 |
url = st.text_input(
|
|
@@ -152,7 +156,7 @@ def body():
|
|
| 152 |
with st.spinner("Downloading audio..."):
|
| 153 |
filename = url.split("/")[-1]
|
| 154 |
os.system(f"wget -q -O {in_path / filename} {url}")
|
| 155 |
-
|
| 156 |
elif option == "Examples":
|
| 157 |
samples_song = load_list_of_songs(path="separate_songs.json")
|
| 158 |
if samples_song is not None:
|
|
@@ -214,13 +218,14 @@ def body():
|
|
| 214 |
execute = st.button(
|
| 215 |
"Separate Music Sources ๐ถ", type="primary", use_container_width=True
|
| 216 |
)
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
|
|
|
| 224 |
with st.spinner("Separating source audio, it will take a while..."):
|
| 225 |
if model_name == "vocal_remover":
|
| 226 |
model, device = load_model(pretrained_model="baseline.pth")
|
|
@@ -251,10 +256,10 @@ def body():
|
|
| 251 |
start_time=start_time,
|
| 252 |
end_time=end_time,
|
| 253 |
)
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
elif name_song is not None and option == "Examples":
|
| 259 |
show_results(model_name, name_song, file_sources)
|
| 260 |
|
|
|
|
| 140 |
help="Supported formats: mp3, wav, ogg, flac.",
|
| 141 |
)
|
| 142 |
if uploaded_file is not None:
|
| 143 |
+
with st.spinner("Loading audio..."):
|
| 144 |
+
with open(in_path / uploaded_file.name, "wb") as f:
|
| 145 |
+
f.write(uploaded_file.getbuffer())
|
| 146 |
+
filename = uploaded_file.name
|
| 147 |
+
st.audio(uploaded_file)
|
| 148 |
|
| 149 |
elif option == "From URL":
|
| 150 |
url = st.text_input(
|
|
|
|
| 156 |
with st.spinner("Downloading audio..."):
|
| 157 |
filename = url.split("/")[-1]
|
| 158 |
os.system(f"wget -q -O {in_path / filename} {url}")
|
| 159 |
+
st_local_audio(in_path / filename, key="input_from_url")
|
| 160 |
elif option == "Examples":
|
| 161 |
samples_song = load_list_of_songs(path="separate_songs.json")
|
| 162 |
if samples_song is not None:
|
|
|
|
| 218 |
execute = st.button(
|
| 219 |
"Separate Music Sources ๐ถ", type="primary", use_container_width=True
|
| 220 |
)
|
| 221 |
+
if execute or st.session_state.executed:
|
| 222 |
+
if execute:
|
| 223 |
+
st.session_state.executed = False
|
| 224 |
|
| 225 |
+
if not st.session_state.executed:
|
| 226 |
+
log.info(f"{option} - Separating {filename} with {separation_mode}...")
|
| 227 |
+
song.export(in_path / filename, format=filename.split(".")[-1])
|
| 228 |
+
with st.columns([1, 1, 1])[1]:
|
| 229 |
with st.spinner("Separating source audio, it will take a while..."):
|
| 230 |
if model_name == "vocal_remover":
|
| 231 |
model, device = load_model(pretrained_model="baseline.pth")
|
|
|
|
| 256 |
start_time=start_time,
|
| 257 |
end_time=end_time,
|
| 258 |
)
|
| 259 |
+
dir_name_output = ".".join(filename.split(".")[:-1])
|
| 260 |
+
filename = None
|
| 261 |
+
st.session_state.executed = True
|
| 262 |
+
show_results(model_name, dir_name_output, file_sources)
|
| 263 |
elif name_song is not None and option == "Examples":
|
| 264 |
show_results(model_name, name_song, file_sources)
|
| 265 |
|