fabiogra
commited on
Commit
·
cc1438e
1
Parent(s):
878b9a1
fix: replace check url and download with requests lib
Browse files- app/helpers.py +2 -10
- app/pages/Separate.py +15 -2
app/helpers.py
CHANGED
|
@@ -28,18 +28,10 @@ def url_is_valid(url):
|
|
| 28 |
if url.startswith("http") is False:
|
| 29 |
st.error("URL should start with http or https.")
|
| 30 |
return False
|
| 31 |
-
|
| 32 |
st.error("Extension not supported.")
|
| 33 |
return False
|
| 34 |
-
|
| 35 |
-
if check_file_availability(url):
|
| 36 |
-
return True
|
| 37 |
-
else:
|
| 38 |
-
st.error("Not able to reach the URL.")
|
| 39 |
-
return False
|
| 40 |
-
except Exception:
|
| 41 |
-
st.error("URL is not valid.")
|
| 42 |
-
return False
|
| 43 |
|
| 44 |
|
| 45 |
@st.cache_data(show_spinner=False)
|
|
|
|
| 28 |
if url.startswith("http") is False:
|
| 29 |
st.error("URL should start with http or https.")
|
| 30 |
return False
|
| 31 |
+
if url.split(".")[-1] not in extensions:
|
| 32 |
st.error("Extension not supported.")
|
| 33 |
return False
|
| 34 |
+
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
|
| 37 |
@st.cache_data(show_spinner=False)
|
app/pages/Separate.py
CHANGED
|
@@ -3,7 +3,9 @@ from pathlib import Path
|
|
| 3 |
from typing import List
|
| 4 |
from loguru import logger as log
|
| 5 |
|
|
|
|
| 6 |
import streamlit as st
|
|
|
|
| 7 |
from footer import footer
|
| 8 |
from header import header
|
| 9 |
from helpers import (
|
|
@@ -152,11 +154,22 @@ def body():
|
|
| 152 |
key="url_input",
|
| 153 |
help="Supported formats: mp3, wav, ogg, flac.",
|
| 154 |
)
|
|
|
|
| 155 |
if url != "" and url_is_valid(url):
|
| 156 |
with st.spinner("Downloading audio..."):
|
| 157 |
filename = url.split("/")[-1]
|
| 158 |
-
|
| 159 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
elif option == "Examples":
|
| 161 |
samples_song = load_list_of_songs(path="separate_songs.json")
|
| 162 |
if samples_song is not None:
|
|
|
|
| 3 |
from typing import List
|
| 4 |
from loguru import logger as log
|
| 5 |
|
| 6 |
+
import requests
|
| 7 |
import streamlit as st
|
| 8 |
+
|
| 9 |
from footer import footer
|
| 10 |
from header import header
|
| 11 |
from helpers import (
|
|
|
|
| 154 |
key="url_input",
|
| 155 |
help="Supported formats: mp3, wav, ogg, flac.",
|
| 156 |
)
|
| 157 |
+
|
| 158 |
if url != "" and url_is_valid(url):
|
| 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")
|
| 175 |
if samples_song is not None:
|