baconnier commited on
Commit
9138597
·
verified ·
1 Parent(s): ad637fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -96
app.py CHANGED
@@ -1,37 +1,15 @@
1
  import gradio as gr
2
  import pandas as pd
3
- from ydata_profiling import ProfileReport
4
  import sweetviz as sv
5
- from dataprep.eda import create_report
6
  import io
7
 
8
  class DataAnalyzer:
9
- def __init__(self):
10
- self.current_df = None
11
-
12
- def generate_profile_report(self, df, minimal=False):
13
- profile = ProfileReport(
14
- df,
15
- minimal=minimal,
16
- title="Pandas Profiling Report",
17
- explorative=True,
18
- dark_mode=True
19
- )
20
- # Get HTML directly as string
21
- return profile.to_html()
22
-
23
  def generate_sweetviz_report(self, df):
24
  report = sv.analyze(df)
25
- # Use StringIO to capture the HTML output
26
  html_io = io.StringIO()
27
  report.show_html(filepath=html_io, open_browser=False)
28
  return html_io.getvalue()
29
 
30
- def generate_dataprep_report(self, df):
31
- report = create_report(df)
32
- # Get HTML directly as string
33
- return report.html()
34
-
35
  def get_dataset_info(self, df):
36
  return {
37
  "Rows": len(df),
@@ -45,102 +23,39 @@ def create_interface():
45
  analyzer = DataAnalyzer()
46
 
47
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
48
- gr.Markdown("""
49
- # Data Analysis Dashboard
50
- Upload your CSV file to generate interactive analysis reports
51
- """)
52
 
53
  with gr.Row():
54
  file_input = gr.File(label="Upload CSV")
55
  dataset_info = gr.JSON(label="Dataset Information")
56
 
57
- with gr.Row():
58
- report_type = gr.Radio(
59
- choices=["Full", "Minimal"],
60
- value="Full",
61
- label="Report Type"
62
- )
63
-
64
  with gr.Tabs():
65
- with gr.TabItem("Pandas Profiling"):
66
- profile_html = gr.HTML()
67
- with gr.TabItem("Sweetviz"):
68
  sweet_html = gr.HTML()
69
- with gr.TabItem("DataPrep"):
70
- prep_html = gr.HTML()
71
 
72
- def process_file(file, report_type):
73
  if file is None:
74
- return None, None, None, None
75
 
76
  try:
77
  df = pd.read_csv(file.name)
78
- analyzer.current_df = df
79
-
80
- # Get dataset info
81
  info = analyzer.get_dataset_info(df)
 
82
 
83
- # Generate reports
84
- minimal = report_type == "Minimal"
85
-
86
- with gr.Progress() as progress:
87
- progress(0, desc="Generating Pandas Profiling report...")
88
- profile_html = analyzer.generate_profile_report(df, minimal)
89
-
90
- progress(0.33, desc="Generating Sweetviz report...")
91
- sweet_html = analyzer.generate_sweetviz_report(df)
92
-
93
- progress(0.66, desc="Generating DataPrep report...")
94
- prep_html = analyzer.generate_dataprep_report(df)
95
-
96
- progress(1.0, desc="Done!")
97
-
98
- return (
99
- info,
100
- profile_html,
101
- sweet_html,
102
- prep_html
103
- )
104
 
105
  except Exception as e:
106
- return str(e), None, None, None
107
 
108
  file_input.change(
109
  fn=process_file,
110
- inputs=[file_input, report_type],
111
- outputs=[dataset_info, profile_html, sweet_html, prep_html]
112
- )
113
-
114
- report_type.change(
115
- fn=process_file,
116
- inputs=[file_input, report_type],
117
- outputs=[dataset_info, profile_html, sweet_html, prep_html]
118
  )
119
 
120
  return demo
121
 
122
- # Add custom CSS for better HTML rendering
123
- custom_css = """
124
- <style>
125
- .report-container {
126
- width: 100%;
127
- height: 800px;
128
- overflow: auto;
129
- }
130
- .report-container iframe {
131
- width: 100%;
132
- height: 100%;
133
- border: none;
134
- }
135
- </style>
136
- """
137
-
138
- # Launch the interface
139
  if __name__ == "__main__":
140
  demo = create_interface()
141
- demo.launch(
142
- share=True, # Enable sharing
143
- height=1000, # Set interface height
144
- show_error=True, # Show detailed error messages
145
- custom_css=custom_css # Apply custom styling
146
- )
 
1
  import gradio as gr
2
  import pandas as pd
 
3
  import sweetviz as sv
 
4
  import io
5
 
6
  class DataAnalyzer:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  def generate_sweetviz_report(self, df):
8
  report = sv.analyze(df)
 
9
  html_io = io.StringIO()
10
  report.show_html(filepath=html_io, open_browser=False)
11
  return html_io.getvalue()
12
 
 
 
 
 
 
13
  def get_dataset_info(self, df):
14
  return {
15
  "Rows": len(df),
 
23
  analyzer = DataAnalyzer()
24
 
25
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
26
+ gr.Markdown("# Data Analysis Dashboard")
 
 
 
27
 
28
  with gr.Row():
29
  file_input = gr.File(label="Upload CSV")
30
  dataset_info = gr.JSON(label="Dataset Information")
31
 
 
 
 
 
 
 
 
32
  with gr.Tabs():
33
+ with gr.TabItem("Sweetviz Report"):
 
 
34
  sweet_html = gr.HTML()
35
+ download_btn = gr.Button("Download Report")
 
36
 
37
+ def process_file(file):
38
  if file is None:
39
+ return None, None
40
 
41
  try:
42
  df = pd.read_csv(file.name)
 
 
 
43
  info = analyzer.get_dataset_info(df)
44
+ report_html = analyzer.generate_sweetviz_report(df)
45
 
46
+ return info, report_html
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
  except Exception as e:
49
+ return str(e), None
50
 
51
  file_input.change(
52
  fn=process_file,
53
+ inputs=[file_input],
54
+ outputs=[dataset_info, sweet_html]
 
 
 
 
 
 
55
  )
56
 
57
  return demo
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  if __name__ == "__main__":
60
  demo = create_interface()
61
+ demo.launch()