Spaces:
Runtime error
Runtime error
Improve error handling
Browse files
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
|
23 |
-
raise gr.Error(f"
|
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]
|