baconnier commited on
Commit
9a72b36
·
verified ·
1 Parent(s): 06105cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -26
app.py CHANGED
@@ -3,41 +3,51 @@ import pandas as pd
3
  import sweetviz as sv
4
  import tempfile
5
  import os
 
6
 
7
  class DataAnalyzer:
8
  def __init__(self):
9
  self.temp_dir = tempfile.mkdtemp()
10
 
11
  def generate_sweetviz_report(self, df):
 
12
  report = sv.analyze(df)
13
- report_path = os.path.join(self.temp_dir, "sweetviz_report.html")
14
  report.show_html(report_path, open_browser=False)
15
 
 
16
  with open(report_path, 'r', encoding='utf-8') as f:
17
  html_content = f.read()
18
 
19
- # Add custom CSS to hide unwanted elements and improve interactivity
20
- custom_css = """
21
- <style>
22
- .container {
23
- width: 100% !important;
24
- max-width: none !important;
25
- padding: 0 !important;
26
- }
27
- .nav-logo {
28
- display: none !important;
29
- }
30
- .dataframe {
31
- width: 100% !important;
32
- }
33
- .dataframe th {
34
- cursor: pointer;
35
- }
36
- </style>
37
- """
38
- html_content = custom_css + html_content
39
-
 
 
 
 
 
 
40
  os.remove(report_path)
 
41
  return html_content
42
 
43
  def create_interface():
@@ -57,7 +67,7 @@ def create_interface():
57
  df = pd.read_csv(file.name)
58
  report = analyzer.generate_sweetviz_report(df)
59
 
60
- # Add wrapper div for better styling
61
  report_with_style = f"""
62
  <div style="height: 800px; overflow: auto; padding: 20px;">
63
  {report}
@@ -79,6 +89,4 @@ def create_interface():
79
 
80
  if __name__ == "__main__":
81
  demo = create_interface()
82
- demo.launch(
83
- show_error=True
84
- )
 
3
  import sweetviz as sv
4
  import tempfile
5
  import os
6
+ import re
7
 
8
  class DataAnalyzer:
9
  def __init__(self):
10
  self.temp_dir = tempfile.mkdtemp()
11
 
12
  def generate_sweetviz_report(self, df):
13
+ # Generate report
14
  report = sv.analyze(df)
15
+ report_path = os.path.join(self.temp_dir, "report.html")
16
  report.show_html(report_path, open_browser=False)
17
 
18
+ # Read and modify the HTML content
19
  with open(report_path, 'r', encoding='utf-8') as f:
20
  html_content = f.read()
21
 
22
+ # Remove logo using regex
23
+ html_content = re.sub(r'<div class="nav-logo">.*?</div>', '', html_content, flags=re.DOTALL)
24
+
25
+ # Add custom CSS to hide logo and improve layout
26
+ custom_css = """
27
+ <style>
28
+ .nav-logo {
29
+ display: none !important;
30
+ }
31
+ .container {
32
+ width: 100% !important;
33
+ max-width: none !important;
34
+ padding: 0 !important;
35
+ }
36
+ .dataframe {
37
+ width: 100% !important;
38
+ }
39
+ .nav {
40
+ padding: 0 !important;
41
+ }
42
+ </style>
43
+ """
44
+
45
+ # Insert custom CSS into head
46
+ html_content = html_content.replace('</head>', f'{custom_css}</head>')
47
+
48
+ # Clean up
49
  os.remove(report_path)
50
+
51
  return html_content
52
 
53
  def create_interface():
 
67
  df = pd.read_csv(file.name)
68
  report = analyzer.generate_sweetviz_report(df)
69
 
70
+ # Wrap report in container with fixed height
71
  report_with_style = f"""
72
  <div style="height: 800px; overflow: auto; padding: 20px;">
73
  {report}
 
89
 
90
  if __name__ == "__main__":
91
  demo = create_interface()
92
+ demo.launch(show_error=True)