Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -151,32 +151,6 @@ def generate_visualization(suggestion, df):
|
|
| 151 |
st.error(f"β οΈ Failed to generate visualization: {e}")
|
| 152 |
return None
|
| 153 |
|
| 154 |
-
# Function to create TXT file
|
| 155 |
-
def create_text_report_with_viz_temp(report, conclusion, visualizations):
|
| 156 |
-
content = f"### Analysis Report\n\n{report}\n\n### Visualizations\n"
|
| 157 |
-
|
| 158 |
-
for i, fig in enumerate(visualizations, start=1):
|
| 159 |
-
fig_title = fig.layout.title.text if fig.layout.title.text else f"Visualization {i}"
|
| 160 |
-
x_axis = fig.layout.xaxis.title.text if fig.layout.xaxis.title.text else "X-axis"
|
| 161 |
-
y_axis = fig.layout.yaxis.title.text if fig.layout.yaxis.title.text else "Y-axis"
|
| 162 |
-
|
| 163 |
-
content += f"\n{i}. {fig_title}\n"
|
| 164 |
-
content += f" - X-axis: {x_axis}\n"
|
| 165 |
-
content += f" - Y-axis: {y_axis}\n"
|
| 166 |
-
|
| 167 |
-
if fig.data:
|
| 168 |
-
trace_types = set(trace.type for trace in fig.data)
|
| 169 |
-
content += f" - Chart Type(s): {', '.join(trace_types)}\n"
|
| 170 |
-
else:
|
| 171 |
-
content += " - No data available in this visualization.\n"
|
| 172 |
-
|
| 173 |
-
content += f"\n\n\n{conclusion}"
|
| 174 |
-
|
| 175 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".txt", mode='w', encoding='utf-8') as temp_txt:
|
| 176 |
-
temp_txt.write(content)
|
| 177 |
-
return temp_txt.name
|
| 178 |
-
|
| 179 |
-
|
| 180 |
def add_stats_to_figure(fig, df, y_axis, chart_type):
|
| 181 |
# Calculate statistics
|
| 182 |
min_val = df[y_axis].min()
|
|
@@ -230,6 +204,33 @@ def add_stats_to_figure(fig, df, y_axis, chart_type):
|
|
| 230 |
return fig
|
| 231 |
|
| 232 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
# Function to create PDF with report text and visualizations
|
| 234 |
def create_pdf_report_with_viz(report, conclusion, visualizations):
|
| 235 |
pdf = FPDF()
|
|
|
|
| 151 |
st.error(f"β οΈ Failed to generate visualization: {e}")
|
| 152 |
return None
|
| 153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
def add_stats_to_figure(fig, df, y_axis, chart_type):
|
| 155 |
# Calculate statistics
|
| 156 |
min_val = df[y_axis].min()
|
|
|
|
| 204 |
return fig
|
| 205 |
|
| 206 |
|
| 207 |
+
# Function to create TXT file
|
| 208 |
+
def create_text_report_with_viz_temp(report, conclusion, visualizations):
|
| 209 |
+
content = f"### Analysis Report\n\n{report}\n\n### Visualizations\n"
|
| 210 |
+
|
| 211 |
+
for i, fig in enumerate(visualizations, start=1):
|
| 212 |
+
fig_title = fig.layout.title.text if fig.layout.title.text else f"Visualization {i}"
|
| 213 |
+
x_axis = fig.layout.xaxis.title.text if fig.layout.xaxis.title.text else "X-axis"
|
| 214 |
+
y_axis = fig.layout.yaxis.title.text if fig.layout.yaxis.title.text else "Y-axis"
|
| 215 |
+
|
| 216 |
+
content += f"\n{i}. {fig_title}\n"
|
| 217 |
+
content += f" - X-axis: {x_axis}\n"
|
| 218 |
+
content += f" - Y-axis: {y_axis}\n"
|
| 219 |
+
|
| 220 |
+
if fig.data:
|
| 221 |
+
trace_types = set(trace.type for trace in fig.data)
|
| 222 |
+
content += f" - Chart Type(s): {', '.join(trace_types)}\n"
|
| 223 |
+
else:
|
| 224 |
+
content += " - No data available in this visualization.\n"
|
| 225 |
+
|
| 226 |
+
content += f"\n\n\n{conclusion}"
|
| 227 |
+
|
| 228 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".txt", mode='w', encoding='utf-8') as temp_txt:
|
| 229 |
+
temp_txt.write(content)
|
| 230 |
+
return temp_txt.name
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
|
| 234 |
# Function to create PDF with report text and visualizations
|
| 235 |
def create_pdf_report_with_viz(report, conclusion, visualizations):
|
| 236 |
pdf = FPDF()
|