hertogateis commited on
Commit
be69684
·
verified ·
1 Parent(s): 1e3aa94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -27
app.py CHANGED
@@ -95,41 +95,30 @@ else:
95
  st.markdown("<p style='font-family:sans-serif;font-size: 1rem;'>Raw TAPAS Answer: </p>", unsafe_allow_html=True)
96
  st.write(raw_answer) # Display the raw TAPAS output
97
 
98
- # Ensure that the output from TAPAS is processed for Plotly
99
  answer = raw_answer.get('answer', '')
100
- aggregator = raw_answer.get('aggregator', '')
101
  coordinates = raw_answer.get('coordinates', [])
102
  cells = raw_answer.get('cells', [])
103
 
104
- # Display relevant data from TAPAS output to be used by Plotly
105
  st.markdown("<p style='font-family:sans-serif;font-size: 1rem;'>Relevant Data for Plotly: </p>", unsafe_allow_html=True)
106
  st.write(f"Answer: {answer}")
107
- st.write(f"Aggregator: {aggregator}")
108
  st.write(f"Coordinates: {coordinates}")
109
  st.write(f"Cells: {cells}")
110
 
111
- # Handle different aggregators
112
- if 'average' in question.lower() or aggregator == 'AVG':
113
- avg_value = df.mean().mean() # Calculate overall average
114
- base_sentence = f"The average for '{question}' is {avg_value:.2f}."
115
- elif 'sum' in question.lower() or aggregator == 'SUM':
116
- total_sum = df.sum().sum() # Calculate overall sum
117
- base_sentence = f"The sum for '{question}' is {total_sum:.2f}."
118
- elif 'max' in question.lower() or aggregator == 'MAX':
119
- max_value = df.max().max() # Find overall max value
120
- base_sentence = f"The maximum value for '{question}' is {max_value:.2f}."
121
- elif 'min' in question.lower() or aggregator == 'MIN':
122
- min_value = df.min().min() # Find overall min value
123
- base_sentence = f"The minimum value for '{question}' is {min_value:.2f}."
124
- elif 'count' in question.lower() or aggregator == 'COUNT':
125
- count_value = df.count().sum() # Count all values
126
- base_sentence = f"The total count of non-null values for '{question}' is {count_value}."
127
- else:
128
- base_sentence = f"The answer from TAPAS for '{question}' is {answer}."
129
 
130
- # Display the final response
131
- st.markdown("<p style='font-family:sans-serif;font-size: 0.9rem;'> Final Generated Response: </p>", unsafe_allow_html=True)
132
- st.success(base_sentence)
 
 
 
133
 
134
  else:
135
  # Handle graph-related questions
@@ -147,9 +136,7 @@ else:
147
  if column in df.columns:
148
  fig = px.line(df, x=df.index, y=column, title=f"Graph of column '{column}'")
149
  st.plotly_chart(fig, use_container_width=True)
150
- st.success(f"Here is the graph of column '{column}'.")
151
 
152
- # Stop further execution after generating the graph
153
  st.stop() # This halts further execution
154
 
155
  except Exception as e:
 
95
  st.markdown("<p style='font-family:sans-serif;font-size: 1rem;'>Raw TAPAS Answer: </p>", unsafe_allow_html=True)
96
  st.write(raw_answer) # Display the raw TAPAS output
97
 
98
+ # Extract relevant values for Plotly
99
  answer = raw_answer.get('answer', '')
 
100
  coordinates = raw_answer.get('coordinates', [])
101
  cells = raw_answer.get('cells', [])
102
 
 
103
  st.markdown("<p style='font-family:sans-serif;font-size: 1rem;'>Relevant Data for Plotly: </p>", unsafe_allow_html=True)
104
  st.write(f"Answer: {answer}")
 
105
  st.write(f"Coordinates: {coordinates}")
106
  st.write(f"Cells: {cells}")
107
 
108
+ # If TAPAS is returning a list of numbers for "average" like you mentioned
109
+ if "average" in question.lower() and cells:
110
+ # Assuming cells are numeric values that can be plotted in a graph
111
+ plot_data = [float(cell) for cell in cells] # Convert cells to numeric data
112
+
113
+ # Create a DataFrame for Plotly
114
+ plot_df = pd.DataFrame({ 'Index': list(range(1, len(plot_data) + 1)), 'Value': plot_data })
 
 
 
 
 
 
 
 
 
 
 
115
 
116
+ # Generate a graph using Plotly
117
+ fig = px.line(plot_df, x='Index', y='Value', title=f"Graph for '{question}'")
118
+ st.plotly_chart(fig, use_container_width=True)
119
+
120
+ else:
121
+ st.write(f"No data to plot for the question: '{question}'")
122
 
123
  else:
124
  # Handle graph-related questions
 
136
  if column in df.columns:
137
  fig = px.line(df, x=df.index, y=column, title=f"Graph of column '{column}'")
138
  st.plotly_chart(fig, use_container_width=True)
 
139
 
 
140
  st.stop() # This halts further execution
141
 
142
  except Exception as e: