baconnier commited on
Commit
276ed24
·
verified ·
1 Parent(s): acc4e78

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -47
app.py CHANGED
@@ -3,7 +3,6 @@ import pandas as pd
3
  import sweetviz as sv
4
  import tempfile
5
  import os
6
- import re
7
 
8
  class DataAnalyzer:
9
  def __init__(self):
@@ -17,42 +16,21 @@ class DataAnalyzer:
17
  with open(report_path, 'r', encoding='utf-8') as f:
18
  html_content = f.read()
19
 
20
- # Remove Sweetviz logo and header
21
- html_content = re.sub(r'<div class="header">.*?</div>', '', html_content, flags=re.DOTALL)
22
- html_content = re.sub(r'<div class="logo">.*?</div>', '', html_content, flags=re.DOTALL)
23
- html_content = re.sub(r'<div class="nav-logo">.*?</div>', '', html_content, flags=re.DOTALL)
24
-
25
- # Additional CSS to hide unwanted elements and improve layout
26
- custom_css = """
27
- <style>
28
- .header, .logo, .nav-logo {
29
- display: none !important;
30
- }
31
- .container {
32
- width: 100% !important;
33
- max-width: none !important;
34
- padding: 0 !important;
35
- margin-top: 0 !important;
36
- }
37
- .nav {
38
- padding-top: 0 !important;
39
- }
40
- .content {
41
- padding-top: 0 !important;
42
- }
43
- .tab-content {
44
- margin-top: 0 !important;
45
- }
46
- </style>
47
  """
48
 
49
- # Insert custom CSS before closing head tag
50
- html_content = html_content.replace('</head>', f'{custom_css}</head>')
51
-
52
- # Clean up
53
  os.remove(report_path)
54
-
55
- return html_content
56
 
57
  def create_interface():
58
  analyzer = DataAnalyzer()
@@ -60,8 +38,13 @@ def create_interface():
60
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
61
  gr.Markdown("# Data Analysis Dashboard")
62
 
63
- file_input = gr.File(label="Upload CSV")
64
- report_html = gr.HTML()
 
 
 
 
 
65
 
66
  def process_file(file):
67
  if file is None:
@@ -69,17 +52,7 @@ def create_interface():
69
 
70
  try:
71
  df = pd.read_csv(file.name)
72
- report = analyzer.generate_sweetviz_report(df)
73
-
74
- # Wrap report in container with fixed height
75
- report_with_style = f"""
76
- <div style="height: 800px; overflow: auto; padding: 0;">
77
- {report}
78
- </div>
79
- """
80
-
81
- return report_with_style
82
-
83
  except Exception as e:
84
  return f"Error generating report: {str(e)}"
85
 
 
3
  import sweetviz as sv
4
  import tempfile
5
  import os
 
6
 
7
  class DataAnalyzer:
8
  def __init__(self):
 
16
  with open(report_path, 'r', encoding='utf-8') as f:
17
  html_content = f.read()
18
 
19
+ # Wrap the report in a table cell with styling
20
+ html_with_table = f"""
21
+ <table width="100%" style="border-collapse: collapse;">
22
+ <tr>
23
+ <td style="padding: 20px; border: 1px solid #ddd;">
24
+ <div style="height: 800px; overflow: auto;">
25
+ {html_content}
26
+ </div>
27
+ </td>
28
+ </tr>
29
+ </table>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  """
31
 
 
 
 
 
32
  os.remove(report_path)
33
+ return html_with_table
 
34
 
35
  def create_interface():
36
  analyzer = DataAnalyzer()
 
38
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
39
  gr.Markdown("# Data Analysis Dashboard")
40
 
41
+ with gr.Tabs():
42
+ with gr.TabItem("Sweetviz Analysis"):
43
+ file_input = gr.File(label="Upload CSV")
44
+ report_html = gr.HTML()
45
+
46
+ with gr.TabItem("Custom Analysis"):
47
+ gr.Markdown("Custom analysis will be added here")
48
 
49
  def process_file(file):
50
  if file is None:
 
52
 
53
  try:
54
  df = pd.read_csv(file.name)
55
+ return analyzer.generate_sweetviz_report(df)
 
 
 
 
 
 
 
 
 
 
56
  except Exception as e:
57
  return f"Error generating report: {str(e)}"
58