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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -23
app.py CHANGED
@@ -15,6 +15,28 @@ class DataAnalyzer:
15
 
16
  with open(report_path, 'r', encoding='utf-8') as f:
17
  html_content = f.read()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  os.remove(report_path)
19
  return html_content
20
 
@@ -24,48 +46,33 @@ def create_interface():
24
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
25
  gr.Markdown("# Data Analysis Dashboard")
26
 
27
- with gr.Row():
28
- file_input = gr.File(label="Upload CSV")
29
- dataset_info = gr.JSON(label="Dataset Information")
30
-
31
- # Correct HTML component initialization
32
- report_html = gr.HTML(label="Analysis Report")
33
 
34
  def process_file(file):
35
  if file is None:
36
- return None, None
37
 
38
  try:
39
  df = pd.read_csv(file.name)
40
-
41
- # Basic dataset info
42
- info = {
43
- "Rows": len(df),
44
- "Columns": len(df.columns),
45
- "Memory Usage (MB)": round(df.memory_usage(deep=True).sum() / 1024**2, 2),
46
- "Missing Values": df.isnull().sum().sum(),
47
- "Column Types": df.dtypes.astype(str).to_dict()
48
- }
49
-
50
- # Generate Sweetviz report
51
  report = analyzer.generate_sweetviz_report(df)
52
 
53
- # Add custom CSS to control height
54
  report_with_style = f"""
55
- <div style="height: 800px; overflow: auto;">
56
  {report}
57
  </div>
58
  """
59
 
60
- return info, report_with_style
61
 
62
  except Exception as e:
63
- return {"error": str(e)}, f"Error generating report: {str(e)}"
64
 
65
  file_input.change(
66
  fn=process_file,
67
  inputs=[file_input],
68
- outputs=[dataset_info, report_html]
69
  )
70
 
71
  return demo
 
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
 
 
46
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
47
  gr.Markdown("# Data Analysis Dashboard")
48
 
49
+ file_input = gr.File(label="Upload CSV")
50
+ report_html = gr.HTML()
 
 
 
 
51
 
52
  def process_file(file):
53
  if file is None:
54
+ return None
55
 
56
  try:
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}
64
  </div>
65
  """
66
 
67
+ return report_with_style
68
 
69
  except Exception as e:
70
+ return f"Error generating report: {str(e)}"
71
 
72
  file_input.change(
73
  fn=process_file,
74
  inputs=[file_input],
75
+ outputs=[report_html]
76
  )
77
 
78
  return demo