twinkle-toes commited on
Commit
1315b1b
1 Parent(s): 3b5c651

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -0
app.py CHANGED
@@ -130,20 +130,25 @@ def load_from_file(path):
130
  try:
131
  obj = json.load(f)
132
  except Exception:
 
133
  return None, True
134
  if not Validator.is_valid_preset(obj):
 
135
  return None, True
136
  return gr.update(selected=1), obj, False
137
 
138
  def load_from_url(url):
139
  resp = requests.get(url)
140
  if not resp.ok:
 
141
  return None, True
142
  try:
143
  obj = json.loads(resp.text)
144
  except Exception:
 
145
  return None, True
146
  if not Validator.is_valid_preset(obj):
 
147
  return None, True
148
  return gr.update(selected=1), obj, False
149
 
 
130
  try:
131
  obj = json.load(f)
132
  except Exception:
133
+ raise gr.Error("File is not valid JSON")
134
  return None, True
135
  if not Validator.is_valid_preset(obj):
136
+ raise gr.Error("File is not a valid preset")
137
  return None, True
138
  return gr.update(selected=1), obj, False
139
 
140
  def load_from_url(url):
141
  resp = requests.get(url)
142
  if not resp.ok:
143
+ raise gr.Error("Failed to load URL")
144
  return None, True
145
  try:
146
  obj = json.loads(resp.text)
147
  except Exception:
148
+ raise gr.Error("URL is not valid JSON")
149
  return None, True
150
  if not Validator.is_valid_preset(obj):
151
+ raise gr.Error("URL is not a valid preset")
152
  return None, True
153
  return gr.update(selected=1), obj, False
154