rameshmoorthy
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,46 @@ import sweetviz as sv
|
|
8 |
from autoviz.AutoViz_Class import AutoViz_Class
|
9 |
from traceml.summary.df import DataFrameSummary
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
def generate_report(file, type):
|
13 |
df = pd.read_csv(file) if file.name.endswith(".csv") else pd.read_excel(file)
|
@@ -87,7 +127,7 @@ def generate_report(file, type):
|
|
87 |
|
88 |
|
89 |
|
90 |
-
return temp_file1.name ,temp_file3.name ,dfviz,sd1
|
91 |
|
92 |
|
93 |
with gr.Blocks() as cluster:
|
@@ -107,11 +147,14 @@ with gr.Blocks() as cluster:
|
|
107 |
gr.HTML(value="""<h1 style="color: #3399FF; text-shadow: 1px 1px 2px #ddd;">SWEETVIZ REPORT</h1>""")
|
108 |
out3=gr.File(label="Download CSV")
|
109 |
with gr.Column():
|
|
|
|
|
|
|
110 |
|
111 |
-
gr.Markdown("Uploaded File")
|
112 |
dataframe1=gr.Dataframe()
|
113 |
with gr.Column():
|
114 |
-
gr.Markdown("Columns Analysis")
|
115 |
dataframe2=gr.Dataframe()
|
116 |
-
btn.click(generate_report,inputs=[file],outputs=[out1,out3,dataframe1,dataframe2])
|
117 |
cluster.launch()
|
|
|
8 |
from autoviz.AutoViz_Class import AutoViz_Class
|
9 |
from traceml.summary.df import DataFrameSummary
|
10 |
|
11 |
+
def variable_table(df):
|
12 |
+
"""
|
13 |
+
Analyzes a DataFrame and categorizes variables with colorful HTML formatting.
|
14 |
+
|
15 |
+
Args:
|
16 |
+
df (pandas.DataFrame): The DataFrame to analyze.
|
17 |
+
|
18 |
+
Returns:
|
19 |
+
str: HTML code representing the analysis results with colorful highlights.
|
20 |
+
"""
|
21 |
+
# Analyze variable types
|
22 |
+
categorical_vars = df.select_dtypes(include=['category', 'object']).columns.tolist()
|
23 |
+
numerical_vars = df.select_dtypes(include=['int64', 'float64']).columns.tolist()
|
24 |
+
text_vars = df.select_dtypes(include=['object']).difference(categorical_vars).tolist()
|
25 |
+
|
26 |
+
# Build HTML table with styles
|
27 |
+
table_style = 'border: 1px solid #ddd; border-collapse: collapse; text-align: left; font-size: 14px;'
|
28 |
+
header_style = 'background-color: #f2f2f2; padding: 5px 10px;'
|
29 |
+
data_style = 'padding: 5px 10px; border-bottom: 1px solid #ddd;'
|
30 |
+
category_color = '#90ee90' # Light green for categorical
|
31 |
+
numerical_color = '#add8e6' # Light blue for numerical
|
32 |
+
text_color = '#ffd9b3' # Light yellow for text
|
33 |
+
|
34 |
+
html = f"<table style='{table_style}'>"
|
35 |
+
html += f"<tr><th style='{header_style}'>Variable Type</th><th style='{header_style}'>Columns</th></tr>"
|
36 |
+
|
37 |
+
# Add rows for each variable type with coloring
|
38 |
+
if categorical_vars:
|
39 |
+
html += f"<tr style='background-color: {category_color};'><td>Categorical</td><td style='{data_style}'>{', '.join(categorical_vars)}</td></tr>"
|
40 |
+
if numerical_vars:
|
41 |
+
html += f"<tr style='background-color: {numerical_color};'><td>Numerical</td><td style='{data_style}'>{', '.join(numerical_vars)}</td></tr>"
|
42 |
+
if text_vars:
|
43 |
+
html += f"<tr style='background-color: {text_color};'><td>Text</td><td style='{data_style}'>{', '.join(text_vars)}</td></tr>"
|
44 |
+
|
45 |
+
# Handle cases where no variables are found
|
46 |
+
if not (categorical_vars or numerical_vars or text_vars):
|
47 |
+
html += "<tr><td>No variables found!</td></tr>"
|
48 |
+
|
49 |
+
html += "</table>"
|
50 |
+
return html
|
51 |
|
52 |
def generate_report(file, type):
|
53 |
df = pd.read_csv(file) if file.name.endswith(".csv") else pd.read_excel(file)
|
|
|
127 |
|
128 |
|
129 |
|
130 |
+
return temp_file1.name ,temp_file3.name ,variable_table(df),dfviz,sd1
|
131 |
|
132 |
|
133 |
with gr.Blocks() as cluster:
|
|
|
147 |
gr.HTML(value="""<h1 style="color: #3399FF; text-shadow: 1px 1px 2px #ddd;">SWEETVIZ REPORT</h1>""")
|
148 |
out3=gr.File(label="Download CSV")
|
149 |
with gr.Column():
|
150 |
+
gr.Markdown("***Uploaded File***")
|
151 |
+
var=gr.HTML()
|
152 |
+
with gr.Column():
|
153 |
|
154 |
+
gr.Markdown("#Uploaded File")
|
155 |
dataframe1=gr.Dataframe()
|
156 |
with gr.Column():
|
157 |
+
gr.Markdown("#Columns Analysis")
|
158 |
dataframe2=gr.Dataframe()
|
159 |
+
btn.click(generate_report,inputs=[file],outputs=[out1,out3,var,dataframe1,dataframe2])
|
160 |
cluster.launch()
|