Update app.py
Browse files
app.py
CHANGED
@@ -32,24 +32,29 @@ def process_file(api_key, file, instructions):
|
|
32 |
# Generate visualizations
|
33 |
images = []
|
34 |
for plot in plots[:3]: # Ensure max 3 plots
|
35 |
-
fig = plt.
|
36 |
title, plot_type, x, y = plot
|
37 |
|
38 |
if plot_type == 'bar':
|
39 |
-
df.plot
|
40 |
elif plot_type == 'line':
|
41 |
-
df.plot
|
42 |
elif plot_type == 'scatter':
|
43 |
-
df.plot
|
44 |
elif plot_type == 'hist':
|
45 |
-
df[y].hist(ax=
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
-
plt.title(title)
|
48 |
buf = io.BytesIO()
|
49 |
-
|
50 |
buf.seek(0)
|
51 |
-
|
52 |
-
|
|
|
53 |
|
54 |
return images if len(images) == 3 else images + [Image.new('RGB', (800, 600), (255,255,255))]*(3-len(images))
|
55 |
|
|
|
32 |
# Generate visualizations
|
33 |
images = []
|
34 |
for plot in plots[:3]: # Ensure max 3 plots
|
35 |
+
fig, ax = plt.subplots(figsize=(10, 6))
|
36 |
title, plot_type, x, y = plot
|
37 |
|
38 |
if plot_type == 'bar':
|
39 |
+
df.plot(kind='bar', x=x, y=y, ax=ax)
|
40 |
elif plot_type == 'line':
|
41 |
+
df.plot(kind='line', x=x, y=y, ax=ax)
|
42 |
elif plot_type == 'scatter':
|
43 |
+
df.plot(kind='scatter', x=x, y=y, ax=ax)
|
44 |
elif plot_type == 'hist':
|
45 |
+
df[y].hist(ax=ax)
|
46 |
+
|
47 |
+
ax.set_title(title)
|
48 |
+
ax.set_xlabel(x)
|
49 |
+
ax.set_ylabel(y)
|
50 |
+
plt.tight_layout()
|
51 |
|
|
|
52 |
buf = io.BytesIO()
|
53 |
+
plt.savefig(buf, format='png')
|
54 |
buf.seek(0)
|
55 |
+
img = Image.open(buf)
|
56 |
+
images.append(img)
|
57 |
+
plt.close(fig)
|
58 |
|
59 |
return images if len(images) == 3 else images + [Image.new('RGB', (800, 600), (255,255,255))]*(3-len(images))
|
60 |
|