karmiq commited on
Commit
d8e3961
·
1 Parent(s): 52b4dce

Improve error handling

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -19,8 +19,8 @@ operations = {"+": add, "-": sub}
19
  def parse_expression(input):
20
  try:
21
  return expression.parseString(input)
22
- except ParseException as pe:
23
- raise gr.Error(f"Syntax error at {pe.loc}: {pe.msg}")
24
 
25
 
26
  def evaluate_expression(input):
@@ -52,6 +52,9 @@ def expression_to_vectors(input):
52
 
53
 
54
  def get_results(expression):
 
 
 
55
  vectors = expression_to_vectors(expression)
56
  similarity_scores = cosine_similarity([vectors], all_vectors)[0]
57
  top_indices = np.argsort(similarity_scores)[::-1]
 
19
  def parse_expression(input):
20
  try:
21
  return expression.parseString(input)
22
+ except ParseException as e:
23
+ raise gr.Error(f"Parsing error: {e.msg} at position [{e.loc}].")
24
 
25
 
26
  def evaluate_expression(input):
 
52
 
53
 
54
  def get_results(expression):
55
+ if len(expression) < 1:
56
+ raise gr.Error("Please provide an expression.")
57
+
58
  vectors = expression_to_vectors(expression)
59
  similarity_scores = cosine_similarity([vectors], all_vectors)[0]
60
  top_indices = np.argsort(similarity_scores)[::-1]