Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -77,11 +77,22 @@ else:
|
|
| 77 |
coordinates = raw_answer.get('coordinates', [])
|
| 78 |
cells = raw_answer.get('cells', [])
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
else:
|
| 86 |
# Construct a base sentence for other aggregators or no aggregation
|
| 87 |
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 |
+
# Handle aggregation based on user question or TAPAS output
|
| 81 |
+
if 'average' in question.lower() or aggregator == 'AVG':
|
| 82 |
+
avg_value = df_numeric.mean().mean() # Calculate average of the entire DataFrame
|
| 83 |
+
base_sentence = f"The average for '{question}' is {avg_value:.2f}."
|
| 84 |
+
elif 'sum' in question.lower() or aggregator == 'SUM':
|
| 85 |
+
total_sum = df_numeric.sum().sum() # Calculate sum of all numeric values
|
| 86 |
+
base_sentence = f"The sum for '{question}' is {total_sum:.2f}."
|
| 87 |
+
elif 'max' in question.lower() or aggregator == 'MAX':
|
| 88 |
+
max_value = df_numeric.max().max() # Calculate max value across DataFrame
|
| 89 |
+
base_sentence = f"The maximum value for '{question}' is {max_value:.2f}."
|
| 90 |
+
elif 'min' in question.lower() or aggregator == 'MIN':
|
| 91 |
+
min_value = df_numeric.min().min() # Calculate min value across DataFrame
|
| 92 |
+
base_sentence = f"The minimum value for '{question}' is {min_value:.2f}."
|
| 93 |
+
elif 'count' in question.lower() or aggregator == 'COUNT':
|
| 94 |
+
row_count = df_numeric.count().sum() # Count of all non-null values
|
| 95 |
+
base_sentence = f"The total count of non-null values for '{question}' is {row_count}."
|
| 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}."
|