Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import streamlit as st
|
|
| 2 |
import pandas as pd
|
| 3 |
import sqlite3
|
| 4 |
import os
|
|
|
|
| 5 |
import json
|
| 6 |
from pathlib import Path
|
| 7 |
import plotly.express as px
|
|
@@ -83,6 +84,37 @@ if st.session_state.df is not None and st.session_state.show_preview:
|
|
| 83 |
st.subheader("π Dataset Preview")
|
| 84 |
st.dataframe(st.session_state.df.head())
|
| 85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
# SQL-RAG Analysis
|
| 87 |
if st.session_state.df is not None:
|
| 88 |
temp_dir = tempfile.TemporaryDirectory()
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import sqlite3
|
| 4 |
import os
|
| 5 |
+
import io
|
| 6 |
import json
|
| 7 |
from pathlib import Path
|
| 8 |
import plotly.express as px
|
|
|
|
| 84 |
st.subheader("π Dataset Preview")
|
| 85 |
st.dataframe(st.session_state.df.head())
|
| 86 |
|
| 87 |
+
|
| 88 |
+
# Helper function to create a plain text report with visualization summaries
|
| 89 |
+
def create_text_report_with_viz(report, conclusion, visualizations):
|
| 90 |
+
content = f"### Analysis Report\n\n{report}\n\n### Conclusion\n\n{conclusion}\n\n### Visualizations\n"
|
| 91 |
+
|
| 92 |
+
# Dynamically add descriptions for each visualization
|
| 93 |
+
for i, fig in enumerate(visualizations, start=1):
|
| 94 |
+
# Extract the title of the Plotly figure if available
|
| 95 |
+
fig_title = fig.layout.title.text if fig.layout.title.text else f"Visualization {i}"
|
| 96 |
+
|
| 97 |
+
# Add title and figure details
|
| 98 |
+
content += f"\n{i}. {fig_title}\n"
|
| 99 |
+
|
| 100 |
+
# Extract x and y axis titles if available
|
| 101 |
+
x_axis = fig.layout.xaxis.title.text if fig.layout.xaxis.title.text else "X-axis"
|
| 102 |
+
y_axis = fig.layout.yaxis.title.text if fig.layout.yaxis.title.text else "Y-axis"
|
| 103 |
+
|
| 104 |
+
content += f" - X-axis: {x_axis}\n"
|
| 105 |
+
content += f" - Y-axis: {y_axis}\n"
|
| 106 |
+
|
| 107 |
+
# If figure has data, summarize it
|
| 108 |
+
if fig.data:
|
| 109 |
+
trace_types = set(trace.type for trace in fig.data)
|
| 110 |
+
content += f" - Chart Type(s): {', '.join(trace_types)}\n"
|
| 111 |
+
else:
|
| 112 |
+
content += " - No data available in this visualization.\n"
|
| 113 |
+
|
| 114 |
+
# Return the content as a downloadable text stream
|
| 115 |
+
return io.BytesIO(content.encode("utf-8"))
|
| 116 |
+
|
| 117 |
+
|
| 118 |
# SQL-RAG Analysis
|
| 119 |
if st.session_state.df is not None:
|
| 120 |
temp_dir = tempfile.TemporaryDirectory()
|