Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -110,44 +110,36 @@ def create_pdf_report_with_viz(report, conclusion, visualizations):
|
|
110 |
pdf.set_font("Arial", size=12)
|
111 |
pdf.multi_cell(0, 10, conclusion)
|
112 |
|
113 |
-
# Add Visualizations
|
114 |
pdf.add_page()
|
115 |
pdf.set_font("Arial", style="B", size=16)
|
116 |
pdf.cell(0, 10, "π Visualizations", ln=True)
|
117 |
pdf.ln(5)
|
118 |
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
# Save the PDF to a temporary file
|
144 |
-
temp_pdf = tempfile.NamedTemporaryFile(delete=False, suffix=".pdf")
|
145 |
-
pdf.output(temp_pdf.name)
|
146 |
-
|
147 |
-
# Clean up temporary images
|
148 |
-
for img_path in temp_images:
|
149 |
-
if os.path.exists(img_path):
|
150 |
-
os.remove(img_path)
|
151 |
|
152 |
return temp_pdf
|
153 |
|
|
|
110 |
pdf.set_font("Arial", size=12)
|
111 |
pdf.multi_cell(0, 10, conclusion)
|
112 |
|
113 |
+
# Add Visualizations
|
114 |
pdf.add_page()
|
115 |
pdf.set_font("Arial", style="B", size=16)
|
116 |
pdf.cell(0, 10, "π Visualizations", ln=True)
|
117 |
pdf.ln(5)
|
118 |
|
119 |
+
with tempfile.TemporaryDirectory() as temp_dir:
|
120 |
+
for i, fig in enumerate(visualizations, start=1):
|
121 |
+
fig_title = fig.layout.title.text if fig.layout.title.text else f"Visualization {i}"
|
122 |
+
x_axis = fig.layout.xaxis.title.text if fig.layout.xaxis.title.text else "X-axis"
|
123 |
+
y_axis = fig.layout.yaxis.title.text if fig.layout.yaxis.title.text else "Y-axis"
|
124 |
+
|
125 |
+
# Save each visualization as a PNG image
|
126 |
+
img_path = os.path.join(temp_dir, f"viz_{i}.png")
|
127 |
+
fig.write_image(img_path)
|
128 |
+
|
129 |
+
# Insert Title and Description
|
130 |
+
pdf.set_font("Arial", style="B", size=14)
|
131 |
+
pdf.multi_cell(0, 10, f"{i}. {fig_title}")
|
132 |
+
pdf.set_font("Arial", size=12)
|
133 |
+
pdf.multi_cell(0, 10, f"X-axis: {x_axis} | Y-axis: {y_axis}")
|
134 |
+
pdf.ln(3)
|
135 |
+
|
136 |
+
# Embed Visualization
|
137 |
+
pdf.image(img_path, w=170)
|
138 |
+
pdf.ln(10)
|
139 |
+
|
140 |
+
# Save PDF
|
141 |
+
temp_pdf = tempfile.NamedTemporaryFile(delete=False, suffix=".pdf")
|
142 |
+
pdf.output(temp_pdf.name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
|
144 |
return temp_pdf
|
145 |
|