mgtotaro commited on
Commit
39fc6e6
·
1 Parent(s): 502a649

improved error handling

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -16,15 +16,24 @@ def app(*argv):
16
  # Unpack the arguments
17
  seq, trg, model_name, *_ = argv
18
  scoring = SCORING[scoring_strategy.value]
 
 
 
 
 
 
 
 
 
 
19
  # Calculate the data based on the input parameters
20
  try:
21
  data = Data(seq, trg, model_name, scoring).calculate()
22
  if isinstance(data.image(), str):
23
- out = Image(value=data.image(), type='filepath', visible=True), DataFrame(visible=False)
24
  else:
25
- out = Image(visible=False), DataFrame(value=data.image(), visible=True)
26
  except Exception as e:
27
- out = Image(visible=False), DataFrame(visible=False)
28
  raise Error(str(e))
29
 
30
  return *out, DownloadButton(value=data.csv(), visible=True)
 
16
  # Unpack the arguments
17
  seq, trg, model_name, *_ = argv
18
  scoring = SCORING[scoring_strategy.value]
19
+
20
+ # Initialise the output
21
+ out = Image(visible=False), DataFrame(visible=False)
22
+
23
+ # Validate the input
24
+ if 1 > len(seq):
25
+ raise Error("Sequence cannot be empty")
26
+ if 1 > len(trg):
27
+ raise Error("Substitutions cannot be empty")
28
+
29
  # Calculate the data based on the input parameters
30
  try:
31
  data = Data(seq, trg, model_name, scoring).calculate()
32
  if isinstance(data.image(), str):
33
+ out = Image(value=data.image(), type='filepath', visible=True), out[1]
34
  else:
35
+ out = out[0], DataFrame(value=data.image(), visible=True)
36
  except Exception as e:
 
37
  raise Error(str(e))
38
 
39
  return *out, DownloadButton(value=data.csv(), visible=True)