Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -19,7 +19,9 @@ class DataAnalyzer:
|
|
19 |
self.AV = AutoViz_Class()
|
20 |
|
21 |
def generate_sweetviz_report(self, df):
|
22 |
-
|
|
|
|
|
23 |
report = sv.analyze(df)
|
24 |
report_path = os.path.join(self.temp_dir, "report.html")
|
25 |
report.show_html(report_path, open_browser=False)
|
@@ -43,20 +45,21 @@ class DataAnalyzer:
|
|
43 |
return html_with_table
|
44 |
|
45 |
def generate_autoviz_report(self, df):
|
46 |
-
|
|
|
|
|
47 |
viz_temp_dir = os.path.join(self.temp_dir, "autoviz_output")
|
48 |
if os.path.exists(viz_temp_dir):
|
49 |
shutil.rmtree(viz_temp_dir)
|
50 |
os.makedirs(viz_temp_dir)
|
51 |
|
52 |
try:
|
53 |
-
|
54 |
-
plt.close('all') # Close any existing plots
|
55 |
dfte = self.AV.AutoViz(
|
56 |
filename='',
|
57 |
sep=',',
|
58 |
depVar='',
|
59 |
-
dfte=df,
|
60 |
header=0,
|
61 |
verbose=0,
|
62 |
lowess=False,
|
@@ -66,7 +69,6 @@ class DataAnalyzer:
|
|
66 |
save_plot_dir=viz_temp_dir
|
67 |
)
|
68 |
|
69 |
-
# Collect generated HTML files
|
70 |
html_parts = []
|
71 |
if os.path.exists(viz_temp_dir):
|
72 |
for file in sorted(os.listdir(viz_temp_dir)):
|
@@ -98,60 +100,64 @@ def create_interface():
|
|
98 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
99 |
gr.Markdown("# Data Analysis Dashboard")
|
100 |
|
101 |
-
#
|
102 |
-
|
103 |
-
report_html = gr.HTML(label="Sweetviz Report")
|
104 |
-
autoviz_html = gr.HTML(label="AutoViz Report")
|
105 |
-
column_dropdown = gr.Dropdown(
|
106 |
-
label="Select Categorical Column",
|
107 |
-
choices=[],
|
108 |
-
interactive=True
|
109 |
-
)
|
110 |
|
111 |
with gr.Tabs():
|
|
|
112 |
with gr.TabItem("Data Upload & Preview"):
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
)
|
128 |
-
plot_output = gr.Image(label="UMAP Visualization")
|
129 |
-
|
130 |
-
def process_file(file):
|
131 |
-
if file is None:
|
132 |
-
return None, None, None, gr.Dropdown(choices=[])
|
133 |
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
|
|
|
|
|
|
|
|
140 |
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
gr.Dropdown(choices=cat_columns)
|
146 |
)
|
147 |
-
except Exception as e:
|
148 |
-
return None, f"Error: {str(e)}", f"Error: {str(e)}", gr.Dropdown(choices=[])
|
149 |
-
|
150 |
-
file_input.change(
|
151 |
-
fn=process_file,
|
152 |
-
inputs=[file_input],
|
153 |
-
outputs=[data_preview, report_html, autoviz_html, column_dropdown]
|
154 |
-
)
|
155 |
|
156 |
return demo
|
157 |
|
|
|
19 |
self.AV = AutoViz_Class()
|
20 |
|
21 |
def generate_sweetviz_report(self, df):
|
22 |
+
if df is None:
|
23 |
+
return "Please upload a dataset first"
|
24 |
+
|
25 |
report = sv.analyze(df)
|
26 |
report_path = os.path.join(self.temp_dir, "report.html")
|
27 |
report.show_html(report_path, open_browser=False)
|
|
|
45 |
return html_with_table
|
46 |
|
47 |
def generate_autoviz_report(self, df):
|
48 |
+
if df is None:
|
49 |
+
return "Please upload a dataset first"
|
50 |
+
|
51 |
viz_temp_dir = os.path.join(self.temp_dir, "autoviz_output")
|
52 |
if os.path.exists(viz_temp_dir):
|
53 |
shutil.rmtree(viz_temp_dir)
|
54 |
os.makedirs(viz_temp_dir)
|
55 |
|
56 |
try:
|
57 |
+
plt.close('all')
|
|
|
58 |
dfte = self.AV.AutoViz(
|
59 |
filename='',
|
60 |
sep=',',
|
61 |
depVar='',
|
62 |
+
dfte=df,
|
63 |
header=0,
|
64 |
verbose=0,
|
65 |
lowess=False,
|
|
|
69 |
save_plot_dir=viz_temp_dir
|
70 |
)
|
71 |
|
|
|
72 |
html_parts = []
|
73 |
if os.path.exists(viz_temp_dir):
|
74 |
for file in sorted(os.listdir(viz_temp_dir)):
|
|
|
100 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
101 |
gr.Markdown("# Data Analysis Dashboard")
|
102 |
|
103 |
+
# Store the dataframe in a state variable
|
104 |
+
current_df = gr.State(None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
with gr.Tabs():
|
107 |
+
# First Tab: Data Upload & Preview
|
108 |
with gr.TabItem("Data Upload & Preview"):
|
109 |
+
with gr.Row():
|
110 |
+
file_input = gr.File(label="Upload CSV")
|
111 |
+
data_preview = gr.Dataframe(label="Data Preview", interactive=False)
|
112 |
+
|
113 |
+
def load_data(file):
|
114 |
+
if file is None:
|
115 |
+
return None, None
|
116 |
+
try:
|
117 |
+
df = pd.read_csv(file.name)
|
118 |
+
return df.head(), df
|
119 |
+
except Exception as e:
|
120 |
+
return None, None
|
121 |
+
|
122 |
+
file_input.change(
|
123 |
+
fn=load_data,
|
124 |
+
inputs=[file_input],
|
125 |
+
outputs=[data_preview, current_df]
|
126 |
+
)
|
127 |
|
128 |
+
# Second Tab: Sweetviz Analysis
|
129 |
+
with gr.TabItem("Sweetviz Analysis"):
|
130 |
+
with gr.Row():
|
131 |
+
sweetviz_button = gr.Button("Generate Sweetviz Report")
|
132 |
+
sweetviz_output = gr.HTML(label="Sweetviz Report")
|
133 |
+
|
134 |
+
def generate_sweetviz(df):
|
135 |
+
if df is None:
|
136 |
+
return "Please upload a dataset first"
|
137 |
+
return analyzer.generate_sweetviz_report(df)
|
138 |
+
|
139 |
+
sweetviz_button.click(
|
140 |
+
fn=generate_sweetviz,
|
141 |
+
inputs=[current_df],
|
142 |
+
outputs=[sweetviz_output]
|
143 |
)
|
|
|
|
|
|
|
|
|
|
|
144 |
|
145 |
+
# Third Tab: AutoViz Analysis
|
146 |
+
with gr.TabItem("AutoViz Analysis"):
|
147 |
+
with gr.Row():
|
148 |
+
autoviz_button = gr.Button("Generate AutoViz Report")
|
149 |
+
autoviz_output = gr.HTML(label="AutoViz Report")
|
150 |
+
|
151 |
+
def generate_autoviz(df):
|
152 |
+
if df is None:
|
153 |
+
return "Please upload a dataset first"
|
154 |
+
return analyzer.generate_autoviz_report(df)
|
155 |
|
156 |
+
autoviz_button.click(
|
157 |
+
fn=generate_autoviz,
|
158 |
+
inputs=[current_df],
|
159 |
+
outputs=[autoviz_output]
|
|
|
160 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
|
162 |
return demo
|
163 |
|