rameshmoorthy commited on
Commit
d4abba2
1 Parent(s): 6d4785c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -66
app.py CHANGED
@@ -4,83 +4,48 @@ import gradio as gr
4
  from pydantic_settings import BaseSettings
5
  from tempfile import NamedTemporaryFile
6
  import sweetviz as sv
7
- # def generate_report(file,type):
8
- # df = pd.read_csv(file) if file.name.endswith(".csv") else pd.read_excel(file)
9
- # if type == "pandas profiling":
10
- # return ydata_profiling.ProfileReport(df).to_html()
11
-
12
- # elif type == "sweetviz":
13
- # return sv.analyze(df).show_html(open_browser=True,
14
- # layout='widescreen',
15
- # scale=None)
16
-
17
- # # Custom HTML template for styling the report output
18
- # custom_html = """
19
- # <!DOCTYPE html>
20
- # <html>
21
- # <head>
22
- # <title>Data Profile Report</title>
23
- # <style>
24
- # body {
25
- # font-family: Arial, sans-serif;
26
- # margin: 0;
27
- # padding: 20px;
28
- # }
29
- # .container {
30
- # width: 80%;
31
- # margin: auto;
32
- # }
33
- # </style>
34
- # </head>
35
- # <body>
36
- # <div class="container">
37
- # {content}
38
- # </div>
39
- # </body>
40
- # </html>
41
- # """
42
-
43
-
44
 
45
  def generate_report(file, type):
46
  df = pd.read_csv(file) if file.name.endswith(".csv") else pd.read_excel(file)
47
- if type == "pandas profiling":
48
- html_report =ydata_profiling.ProfileReport(df).to_html()
49
 
50
- temp_file = NamedTemporaryFile(delete=False, suffix=".html")
51
- temp_file.write(html_report.encode('utf-8'))
52
- temp_file.close()
53
- return temp_file.name ,html_report
 
54
 
55
-
 
 
 
 
 
56
 
57
- # cluster = gr.Interface(
58
- # fn=generate_report,
59
- # inputs=[gr.File(file_types=['.csv', '.xlsx'], label="Upload a CSV or Excel file"),
60
- # gr.Radio(["pandas profiling", "sweetviz"], label="Type of report", info="Explore the data")],
61
- # css="""
62
- # # Output container styling for better visual presentation (optional)
63
- # .output-container {
64
- # padding: 10px;
65
- # }
66
- # """,
67
- # layout=gr.Column(
68
- # 'html',
69
- # #gr.HTML(label="Data Profile Report", html_content=download_html),
70
- # #gr.Button(value="Download Report", type="submit") # Optional: Replace button within HTML if needed
71
- # ),
72
- # title="Excel sheet Profiling Report",
73
- # live=True,
74
- # )
75
  with gr.Blocks() as cluster:
76
  with gr.Column():
77
 
78
  with gr.Row():
79
  file=gr.File(file_types=['.csv', '.xlsx'], label="Upload a CSV or Excel file")
80
- type=gr.Radio(["pandas profiling", "sweetviz"], label="Type of report", info="Explore the data")
81
  btn=gr.Button(value="Download Report")
82
- dwn=gr.File(label="Download CSV")
83
  with gr.Row():
84
- out=gr.HTML()
85
- btn.click(generate_report,inputs=[file,type],outputs=[dwn,out])
 
 
 
 
 
 
 
86
  cluster.launch()
 
4
  from pydantic_settings import BaseSettings
5
  from tempfile import NamedTemporaryFile
6
  import sweetviz as sv
7
+ from dataprep.datasets import load_dataset
8
+ from dataprep.eda import create_report
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  def generate_report(file, type):
11
  df = pd.read_csv(file) if file.name.endswith(".csv") else pd.read_excel(file)
 
 
12
 
13
+ pandas_html_report =ydata_profiling.ProfileReport(df).to_html()
14
+ temp_file1 = NamedTemporaryFile(delete=False, suffix=".html")
15
+ temp_file1.write(pandas_html_report.encode('utf-8'))
16
+ temp_file1.close()
17
+
18
 
19
+ dataprep_report = create_report(df)
20
+ temp_file2 = NamedTemporaryFile(delete=False, suffix=".html")
21
+ temp_file2.write(dataprep_report.encode('utf-8'))
22
+ temp_file2.close()
23
+
24
+
25
 
26
+ sweetviz_report = sv.analyze(df)
27
+ temp_file3 = NamedTemporaryFile(delete=False, suffix=".html")
28
+ temp_file3.write(sweetviz_report.encode('utf-8'))
29
+ temp_file3.close()
30
+
31
+ return temp_file1.name ,temp_file2.name ,temp_file3.nam
32
+
33
+
 
 
 
 
 
 
 
 
 
 
34
  with gr.Blocks() as cluster:
35
  with gr.Column():
36
 
37
  with gr.Row():
38
  file=gr.File(file_types=['.csv', '.xlsx'], label="Upload a CSV or Excel file")
 
39
  btn=gr.Button(value="Download Report")
40
+
41
  with gr.Row():
42
+
43
+
44
+ gr.HTML(html_content="""<h1 style="color: #3399FF; text-shadow: 1px 1px 2px #ddd;">PANDAS REPORT</h1>""")
45
+ out1=gr.File(label="Download CSV")
46
+ gr.HTML(html_content="""<h1 style="color: #3399FF; text-shadow: 1px 1px 2px #ddd;">DATAPREP REPORT</h1>""")
47
+ out2=gr.File(label="Download CSV")
48
+ gr.HTML(html_content="""<h1 style="color: #3399FF; text-shadow: 1px 1px 2px #ddd;">SWEETVIZ REPORT</h1>""")
49
+ out3=gr.File(label="Download CSV")
50
+ btn.click(generate_report,inputs=[file,type],outputs=[out1,out2,out3])
51
  cluster.launch()