hertogateis commited on
Commit
d94b8e2
·
verified ·
1 Parent(s): a6e10e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -10
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
- 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}."
 
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}."