Kryptone commited on
Commit
2bc2108
·
verified ·
1 Parent(s): a1d04a3

add error checking for mvsep

Browse files
Files changed (1) hide show
  1. app.py +24 -18
app.py CHANGED
@@ -211,26 +211,32 @@ def mvsep_api_request(mvsep_key, audio_file, sep_int):
211
  return f"Request sent successfully! Your hash is: {hash_val}.\n\nUse the next tab to check the status of your request."
212
 
213
  def mvsep_check_request(hash_textbox):
214
- url = "https://mvsep.com/api/separation/get"
215
- params = {
216
- "hash": hash_textbox
217
- }
218
- r = requests.get(url, params=params)
219
- rjson = r.json()
220
- success = rjson['success']
221
- status = rjson['status']
222
- return f"Was successful? {str(success)}.\n Status: {status}."
 
 
 
223
 
224
  def mvsep_download_separated_audio(hash_textbox):
225
- url = "https://mvsep.com/api/separation/get"
226
- params = {
227
- "hash": hash_textbox
228
- }
229
- r = requests.get(url, params=params)
230
- rjson = r.json()
231
- files = rjson.get('data', {}).get('files', [])
232
- urls = [file['url'] for file in files]
233
- return json.dumps(urls, indent=4)
 
 
 
234
 
235
 
236
  with gr.Blocks(theme='sudeepshouche/minimalist', title="Global Dataset Maker") as app:
 
211
  return f"Request sent successfully! Your hash is: {hash_val}.\n\nUse the next tab to check the status of your request."
212
 
213
  def mvsep_check_request(hash_textbox):
214
+ try:
215
+ url = "https://mvsep.com/api/separation/get"
216
+ params = {
217
+ "hash": hash_textbox
218
+ }
219
+ r = requests.get(url, params=params)
220
+ rjson = r.json()
221
+ success = rjson['success']
222
+ status = rjson['status']
223
+ return f"Was successful? {str(success)}.\n Status: {status}."
224
+ except requests.exceptions.JSONDecodeError:
225
+ return gr.Info("Status not available or request not sent.")
226
 
227
  def mvsep_download_separated_audio(hash_textbox):
228
+ try:
229
+ url = "https://mvsep.com/api/separation/get"
230
+ params = {
231
+ "hash": hash_textbox
232
+ }
233
+ r = requests.get(url, params=params)
234
+ rjson = r.json()
235
+ files = rjson.get('data', {}).get('files', [])
236
+ urls = [file['url'] for file in files]
237
+ return json.dumps(urls, indent=4)
238
+ except requests.exceptions.JSONDecodeError:
239
+ return gr.Info("Nothing to download yet. Check back later.")
240
 
241
 
242
  with gr.Blocks(theme='sudeepshouche/minimalist', title="Global Dataset Maker") as app: