Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -77,22 +77,42 @@ else:
|
|
77 |
coordinates = raw_answer.get('coordinates', [])
|
78 |
cells = raw_answer.get('cells', [])
|
79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
# Handle aggregation based on user question or TAPAS output
|
81 |
if 'average' in question.lower() or aggregator == 'AVG':
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
84 |
elif 'sum' in question.lower() or aggregator == 'SUM':
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
87 |
elif 'max' in question.lower() or aggregator == 'MAX':
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
90 |
elif 'min' in question.lower() or aggregator == 'MIN':
|
91 |
-
|
92 |
-
|
|
|
|
|
|
|
93 |
elif 'count' in question.lower() or aggregator == 'COUNT':
|
94 |
-
|
95 |
-
base_sentence = f"The total count of
|
96 |
else:
|
97 |
# Construct a base sentence for other aggregators or no aggregation
|
98 |
base_sentence = f"The answer from TAPAS for '{question}' is {answer}."
|
|
|
77 |
coordinates = raw_answer.get('coordinates', [])
|
78 |
cells = raw_answer.get('cells', [])
|
79 |
|
80 |
+
# Check if the answer contains non-numeric values, and filter them out
|
81 |
+
numeric_cells = []
|
82 |
+
for cell in cells:
|
83 |
+
try:
|
84 |
+
numeric_cells.append(float(cell)) # Convert to float if possible
|
85 |
+
except ValueError:
|
86 |
+
pass # Ignore non-numeric cells
|
87 |
+
|
88 |
# Handle aggregation based on user question or TAPAS output
|
89 |
if 'average' in question.lower() or aggregator == 'AVG':
|
90 |
+
if numeric_cells:
|
91 |
+
avg_value = sum(numeric_cells) / len(numeric_cells) # Calculate average
|
92 |
+
base_sentence = f"The average for '{question}' is {avg_value:.2f}."
|
93 |
+
else:
|
94 |
+
base_sentence = f"No numeric data found for calculating the average of '{question}'."
|
95 |
elif 'sum' in question.lower() or aggregator == 'SUM':
|
96 |
+
if numeric_cells:
|
97 |
+
total_sum = sum(numeric_cells) # Calculate sum
|
98 |
+
base_sentence = f"The sum for '{question}' is {total_sum:.2f}."
|
99 |
+
else:
|
100 |
+
base_sentence = f"No numeric data found for calculating the sum of '{question}'."
|
101 |
elif 'max' in question.lower() or aggregator == 'MAX':
|
102 |
+
if numeric_cells:
|
103 |
+
max_value = max(numeric_cells) # Find max value
|
104 |
+
base_sentence = f"The maximum value for '{question}' is {max_value:.2f}."
|
105 |
+
else:
|
106 |
+
base_sentence = f"No numeric data found for finding the maximum value of '{question}'."
|
107 |
elif 'min' in question.lower() or aggregator == 'MIN':
|
108 |
+
if numeric_cells:
|
109 |
+
min_value = min(numeric_cells) # Find min value
|
110 |
+
base_sentence = f"The minimum value for '{question}' is {min_value:.2f}."
|
111 |
+
else:
|
112 |
+
base_sentence = f"No numeric data found for finding the minimum value of '{question}'."
|
113 |
elif 'count' in question.lower() or aggregator == 'COUNT':
|
114 |
+
count_value = len(numeric_cells) # Count numeric cells
|
115 |
+
base_sentence = f"The total count of numeric values for '{question}' is {count_value}."
|
116 |
else:
|
117 |
# Construct a base sentence for other aggregators or no aggregation
|
118 |
base_sentence = f"The answer from TAPAS for '{question}' is {answer}."
|