Spaces:
Running
Running
fabiogra
commited on
Commit
·
9baeeda
1
Parent(s):
cc1438e
feat: check file from url dimension
Browse files- app/helpers.py +10 -0
- app/pages/Separate.py +3 -3
app/helpers.py
CHANGED
@@ -163,3 +163,13 @@ def st_local_audio(pathname, key):
|
|
163 |
},
|
164 |
key=key,
|
165 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
},
|
164 |
key=key,
|
165 |
)
|
166 |
+
|
167 |
+
|
168 |
+
def file_size_is_valid(response):
|
169 |
+
file_size = response.headers.get("Content-Length")
|
170 |
+
file_size = int(file_size)
|
171 |
+
max_size_mb = int(os.environ["STREAMLIT_SERVER_MAX_UPLOAD_SIZE"])
|
172 |
+
if max_size_mb and file_size > max_size_mb * 1024 * 1024:
|
173 |
+
st.error(
|
174 |
+
f"The file is too large to download. Maximum size allowed: {max_size_mb}MB. Duplicate this space to remove any limit."
|
175 |
+
)
|
app/pages/Separate.py
CHANGED
@@ -14,6 +14,7 @@ from helpers import (
|
|
14 |
plot_audio,
|
15 |
st_local_audio,
|
16 |
url_is_valid,
|
|
|
17 |
)
|
18 |
from service.demucs_runner import separator
|
19 |
from service.vocal_remover.runner import load_model, separate
|
@@ -159,16 +160,15 @@ def body():
|
|
159 |
with st.spinner("Downloading audio..."):
|
160 |
filename = url.split("/")[-1]
|
161 |
response = requests.get(url, stream=True)
|
162 |
-
|
163 |
-
if response.status_code == 200:
|
164 |
with open(in_path / filename, "wb") as audio_file:
|
165 |
for chunk in response.iter_content(chunk_size=1024):
|
166 |
if chunk:
|
167 |
audio_file.write(chunk)
|
168 |
-
|
169 |
st_local_audio(in_path / filename, key="input_from_url")
|
170 |
else:
|
171 |
st.error("Failed to download audio file.")
|
|
|
172 |
|
173 |
elif option == "Examples":
|
174 |
samples_song = load_list_of_songs(path="separate_songs.json")
|
|
|
14 |
plot_audio,
|
15 |
st_local_audio,
|
16 |
url_is_valid,
|
17 |
+
file_size_is_valid,
|
18 |
)
|
19 |
from service.demucs_runner import separator
|
20 |
from service.vocal_remover.runner import load_model, separate
|
|
|
160 |
with st.spinner("Downloading audio..."):
|
161 |
filename = url.split("/")[-1]
|
162 |
response = requests.get(url, stream=True)
|
163 |
+
if response.status_code == 200 and file_size_is_valid(response):
|
|
|
164 |
with open(in_path / filename, "wb") as audio_file:
|
165 |
for chunk in response.iter_content(chunk_size=1024):
|
166 |
if chunk:
|
167 |
audio_file.write(chunk)
|
|
|
168 |
st_local_audio(in_path / filename, key="input_from_url")
|
169 |
else:
|
170 |
st.error("Failed to download audio file.")
|
171 |
+
filename = None
|
172 |
|
173 |
elif option == "Examples":
|
174 |
samples_song = load_list_of_songs(path="separate_songs.json")
|