File size: 3,639 Bytes
0a5d39a
7a75289
0a5d39a
71c9026
dd375ae
1065d81
bbe3128
 
 
c335d03
b9cae72
 
 
a899a25
d4abba2
 
 
 
3275b57
b9cae72
e7f020c
 
 
 
d4abba2
3275b57
 
 
 
 
 
 
 
0a5d39a
d4abba2
8cc8a10
cb63445
3cd0174
aff03dd
 
 
3cd0174
 
 
 
3275b57
af6630f
3cd0174
d4abba2
0d398ac
d4abba2
c335d03
bbe3128
 
 
 
 
 
0895bff
 
bbe3128
 
 
0895bff
bbe3128
 
92c8cf6
bbe3128
 
c335d03
 
 
 
31200cf
 
 
ab0b63c
 
 
 
 
 
 
 
 
c335d03
31200cf
d4abba2
 
a899a25
a141a8d
 
 
 
 
d4abba2
a141a8d
d4abba2
 
492d55e
d4abba2
492d55e
d4abba2
492d55e
d4abba2
c335d03
31200cf
8e06dbc
31200cf
 
8e06dbc
31200cf
bbe3128
b9cae72
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import pandas as pd
import ydata_profiling
import gradio as gr
from pydantic_settings import BaseSettings
from tempfile import NamedTemporaryFile
import sweetviz as sv
#from datatile.summary.df import DataFrameSummary
from autoviz.AutoViz_Class import AutoViz_Class
from traceml.summary.df import DataFrameSummary


def generate_report(file, type):
    df = pd.read_csv(file) if file.name.endswith(".csv") else pd.read_excel(file)

    pandas_html_report =ydata_profiling.ProfileReport(df).to_html() 
    temp_file1 = NamedTemporaryFile(delete=False, suffix=".html")
    temp_file1.write(pandas_html_report.encode('utf-8'))
    temp_file1.close()
    print('Pandas completed')
    
    # dataprep_report = create_report(df)
    # temp_file2 = NamedTemporaryFile(delete=False, suffix=".html")
    # temp_file2.write(dataprep_report.encode('utf-8'))
    # temp_file2.close()

    def convert_mixed_to_str(df):
  
      mixed_cols = df.select_dtypes(include=['object']).columns  # Detect object dtype (usually mixed)
      for col in mixed_cols:
        df[col] = df[col].astype(str)  # Convert mixed columns to strings
      return df

    df = convert_mixed_to_str(df.copy())

    sweetviz_report = sv.analyze(df)
    #sweetviz_report=sweetviz_report.show_html()
    #print(type(sweetviz_report))
    report=sweetviz_report.show_html(  filepath='SWEETVIZ_REPORT.html', 
            open_browser=False, 
            layout='widescreen', 
            scale=None)
    HTMLFileToBeOpened = open('SWEETVIZ_REPORT.html', "r") 
  
    # Reading the file and storing in a variable 
    contents = HTMLFileToBeOpened.read() 
    print('Pandas completed')
    
  
    temp_file3 = NamedTemporaryFile(delete=False, suffix=".html")
    temp_file3.write(contents.encode('utf-8'))
    temp_file3.close()

    #AUTOVIZ
    AV = AutoViz_Class()

    dfviz = AV.AutoViz(
    "",
    sep=",",
    depVar="",
    dfte=df,
    header=0,
    verbose=2,
    lowess=False,
    chart_format="html",
    max_rows_analyzed=500,
    max_cols_analyzed=20,
    save_plot_dir="plots"
    )

    
    
   
    dfs = DataFrameSummary(df)
    sd=dfs.summary()
    sd.index.name = 'Parameters'
    sd1= sd.reset_index(drop=False)
    def highlight_cols(x): 
        df = x.copy() 
        df.loc[:, :] = 'color: purple'
        df[['Parameters']] = 'color: red'
        return df 

    # Applying the style function
    sd1 = sd1.style.apply(highlight_cols, axis = None)

    
    return temp_file1.name  ,temp_file3.name ,dfviz,sd1
    
     
with gr.Blocks() as cluster:
    with gr.Column():
        
        with gr.Row():
            file=gr.File(file_types=['.csv', '.xlsx'], label="Upload a CSV or Excel file")
            btn=gr.Button(value="Download Report") 
            
        with gr.Row():
            
            
            gr.HTML(value="""<h1 style="color: #3399FF; text-shadow: 1px 1px 2px #ddd;">PANDAS REPORT</h1>""")
            out1=gr.File(label="Download CSV")
            gr.HTML(value="""<h1 style="color: #3399FF; text-shadow: 1px 1px 2px #ddd;">DATAPREP REPORT</h1>""")
            out2=gr.File(label="Download CSV")
            gr.HTML(value="""<h1 style="color: #3399FF; text-shadow: 1px 1px 2px #ddd;">SWEETVIZ REPORT</h1>""")
            out3=gr.File(label="Download CSV")
        with gr.Row():
            with gr.Column():
                gr.Markdown("Uploaded File")
                dataframe1=gr.Dataframe()
            with gr.Column():
                gr.Markdown("Columns Analysis")
                dataframe2=gr.Dataframe()
    btn.click(generate_report,inputs=[file],outputs=[out1,out3,dataframe1,dataframe2])
cluster.launch()