Mikasa06 commited on
Commit
d56288c
·
verified ·
1 Parent(s): 406ee2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -4
app.py CHANGED
@@ -93,7 +93,7 @@ def generate_scatter_plot_with_labels(x_values: list[float], y_values: list[floa
93
  y_label: Label for the y-axis (default is 'Y-Axis').
94
 
95
  Returns:
96
- PILImage Object
97
  """
98
  try:
99
  if len(x_values) != len(y_values) or len(x_values) != len(labels):
@@ -132,7 +132,7 @@ def generate_scatter_plot_with_labels(x_values: list[float], y_values: list[floa
132
 
133
  @tool
134
  def generate_line_plot(x_values: list[float], y_values: list[float], title: str = 'Line Plot', x_label: str = 'X-Axis', y_label: str = 'Y-Axis') -> PILImage:
135
- """Generates a line plot.
136
 
137
  Args:
138
  x_values: A list of numerical values for the x-axis.
@@ -141,7 +141,7 @@ def generate_line_plot(x_values: list[float], y_values: list[float], title: str
141
  x_label: Label for the x-axis.
142
  y_label: Label for the y-axis.
143
  Returns:
144
- An Image object containing the line plot.
145
  """
146
  try:
147
  plt.plot(x_values, y_values, marker='o', linestyle='-', color='b')
@@ -161,6 +161,90 @@ def generate_line_plot(x_values: list[float], y_values: list[float], title: str
161
  except Exception as e:
162
  print(f"Error generating line plot: {str(e)}")
163
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
 
165
 
166
 
@@ -185,7 +269,7 @@ with open("prompts.yaml", 'r') as stream:
185
 
186
  agent = CodeAgent(
187
  model=model,
188
- tools=[final_answer,generate_bar_chart,generate_scatter_plot_with_labels,generate_line_plot], ## add your tools here (don't remove final answer)
189
  max_steps=6,
190
  verbosity_level=1,
191
  grammar=None,
 
93
  y_label: Label for the y-axis (default is 'Y-Axis').
94
 
95
  Returns:
96
+ an image of the scatter plot.
97
  """
98
  try:
99
  if len(x_values) != len(y_values) or len(x_values) != len(labels):
 
132
 
133
  @tool
134
  def generate_line_plot(x_values: list[float], y_values: list[float], title: str = 'Line Plot', x_label: str = 'X-Axis', y_label: str = 'Y-Axis') -> PILImage:
135
+ """Generates a line plot from the provided x and y values.
136
 
137
  Args:
138
  x_values: A list of numerical values for the x-axis.
 
141
  x_label: Label for the x-axis.
142
  y_label: Label for the y-axis.
143
  Returns:
144
+ an image of the line plot.
145
  """
146
  try:
147
  plt.plot(x_values, y_values, marker='o', linestyle='-', color='b')
 
161
  except Exception as e:
162
  print(f"Error generating line plot: {str(e)}")
163
 
164
+ @tool
165
+ def generate_histogram(data: list[float], bins: int = 10, title: str = 'Histogram', x_label: str = 'Values', y_label: str = 'Frequency') -> PILImage:
166
+ """Generates a histogram from the provided data and bins values.
167
+
168
+ Args:
169
+ data: A list of numerical values.
170
+ bins: Number of bins for the histogram.
171
+ title: Title for the histogram.
172
+ x_label: Label for the x-axis.
173
+ y_label: Label for the y-axis.
174
+ Returns:
175
+ an image of the histogram plot.
176
+ """
177
+ try:
178
+ plt.hist(data, bins=bins, color='purple', edgecolor='black', alpha=0.7)
179
+ plt.title(title)
180
+ plt.xlabel(x_label)
181
+ plt.ylabel(y_label)
182
+
183
+ img_buffer = io.BytesIO()
184
+ plt.savefig(img_buffer, format='png', dpi=300, bbox_inches='tight')
185
+ plt.close()
186
+
187
+ img_buffer.seek(0)
188
+ img = PILImage.open(img_buffer)
189
+ return img
190
+
191
+ except Exception as e:
192
+ print(f"Error generating histogram: {str(e)}")
193
+
194
+ @tool
195
+ def generate_pie_chart(labels: list[str], values: list[float], title: str = 'Pie Chart') -> PILImage:
196
+ """Generates a pie chart from the provided labels and values.
197
+
198
+ Args:
199
+ labels: A list of category labels.
200
+ values: A list of numerical values for each category.
201
+ title: Title for the pie chart.
202
+ Returns:
203
+ an image of the pie chart.
204
+ """
205
+ try:
206
+ plt.pie(values, labels=labels, autopct='%1.1f%%', startangle=140, colors=['blue', 'red', 'green', 'yellow'])
207
+ plt.title(title)
208
+ plt.axis('equal')
209
+
210
+ img_buffer = io.BytesIO()
211
+ plt.savefig(img_buffer, format='png', dpi=300, bbox_inches='tight')
212
+ plt.close()
213
+
214
+ img_buffer.seek(0)
215
+ img = PILImage.open(img_buffer)
216
+ return img
217
+
218
+ except Exception as e:
219
+ print(f"Error generating pie chart: {str(e)}")
220
+
221
+ @tool
222
+ def generate_box_plot(data: list[list[float]], title: str = 'Box Plot', y_label: str = 'Values') -> PILImage:
223
+ """Generates a box plot from the provided data.
224
+
225
+ Args:
226
+ data: A list of numerical lists representing different categories.
227
+ title: Title for the box plot.
228
+ y_label: Label for the y-axis.
229
+ Returns:
230
+ Aan image of the box plot.
231
+ """
232
+ try:
233
+ plt.boxplot(data)
234
+ plt.title(title)
235
+ plt.ylabel(y_label)
236
+
237
+ img_buffer = io.BytesIO()
238
+ plt.savefig(img_buffer, format='png', dpi=300, bbox_inches='tight')
239
+ plt.close()
240
+
241
+ img_buffer.seek(0)
242
+ img = PILImage.open(img_buffer)
243
+ return img
244
+
245
+ except Exception as e:
246
+ print(f"Error generating box plot: {str(e)}")
247
+
248
 
249
 
250
 
 
269
 
270
  agent = CodeAgent(
271
  model=model,
272
+ tools=[final_answer,generate_bar_chart,generate_scatter_plot_with_labels,generate_line_plot,generate_histogram,generate_pie_chart,generate_box_plot], ## add your tools here (don't remove final answer)
273
  max_steps=6,
274
  verbosity_level=1,
275
  grammar=None,