reab5555 commited on
Commit
dffaefe
1 Parent(s): cf863d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -17
app.py CHANGED
@@ -8,21 +8,21 @@ import tempfile
8
  def clean_and_visualize(file, progress=gr.Progress()):
9
  # Load the data
10
  df = pd.read_csv(file.name)
11
-
12
  # Clean the data
13
  cleaned_df = None
14
  nonconforming_cells_before = None
15
  process_times = None
16
  removed_columns = None
17
  removed_rows = None
18
-
19
  for progress_value, status_text in clean_data(df):
20
  if isinstance(status_text, tuple):
21
  cleaned_df, nonconforming_cells_before, process_times, removed_columns, removed_rows = status_text
22
  progress(progress_value, desc="Cleaning completed")
23
  else:
24
  progress(progress_value, desc=status_text)
25
-
26
  # Generate full visualization report
27
  create_full_report(
28
  df,
@@ -32,47 +32,58 @@ def clean_and_visualize(file, progress=gr.Progress()):
32
  removed_columns,
33
  removed_rows
34
  )
35
-
36
  # Save cleaned DataFrame to a temporary CSV file
37
  with tempfile.NamedTemporaryFile(delete=False, suffix='.csv') as tmp_file:
38
  cleaned_df.to_csv(tmp_file.name, index=False)
39
  cleaned_csv_path = tmp_file.name
40
-
41
  # Collect all generated images
42
  image_files = [os.path.join(REPORT_DIR, f) for f in os.listdir(REPORT_DIR) if f.endswith('.png')]
43
-
44
  return cleaned_csv_path, image_files
45
 
46
  def launch_app():
47
  with gr.Blocks() as app:
48
  gr.Markdown("# Data Cleaning and Visualization App")
49
-
50
  with gr.Row():
51
  file_input = gr.File(label="Upload CSV File", file_count="single", file_types=[".csv"])
52
-
53
  with gr.Row():
54
  clean_button = gr.Button("Start Cleaning")
55
-
56
  with gr.Row():
57
  progress_bar = gr.Progress()
58
-
59
  with gr.Row():
60
  cleaned_file_output = gr.File(label="Cleaned CSV", visible=True)
61
-
62
  with gr.Row():
63
- output_gallery = gr.Gallery(label="Visualization Results", show_label=True, elem_id="gallery", columns=[1],
64
- rows=[1], object_fit="contain", height="auto")
65
-
 
 
 
 
 
 
 
 
66
  def process_and_show_results(file):
67
  cleaned_csv_path, image_files = clean_and_visualize(file, progress=progress_bar)
68
- return cleaned_csv_path, image_files
69
-
 
 
 
70
  clean_button.click(
71
  fn=process_and_show_results,
72
  inputs=file_input,
73
  outputs=[cleaned_file_output, output_gallery]
74
  )
75
-
76
  app.launch()
77
 
78
  if __name__ == "__main__":
 
8
  def clean_and_visualize(file, progress=gr.Progress()):
9
  # Load the data
10
  df = pd.read_csv(file.name)
11
+
12
  # Clean the data
13
  cleaned_df = None
14
  nonconforming_cells_before = None
15
  process_times = None
16
  removed_columns = None
17
  removed_rows = None
18
+
19
  for progress_value, status_text in clean_data(df):
20
  if isinstance(status_text, tuple):
21
  cleaned_df, nonconforming_cells_before, process_times, removed_columns, removed_rows = status_text
22
  progress(progress_value, desc="Cleaning completed")
23
  else:
24
  progress(progress_value, desc=status_text)
25
+
26
  # Generate full visualization report
27
  create_full_report(
28
  df,
 
32
  removed_columns,
33
  removed_rows
34
  )
35
+
36
  # Save cleaned DataFrame to a temporary CSV file
37
  with tempfile.NamedTemporaryFile(delete=False, suffix='.csv') as tmp_file:
38
  cleaned_df.to_csv(tmp_file.name, index=False)
39
  cleaned_csv_path = tmp_file.name
40
+
41
  # Collect all generated images
42
  image_files = [os.path.join(REPORT_DIR, f) for f in os.listdir(REPORT_DIR) if f.endswith('.png')]
43
+
44
  return cleaned_csv_path, image_files
45
 
46
  def launch_app():
47
  with gr.Blocks() as app:
48
  gr.Markdown("# Data Cleaning and Visualization App")
49
+
50
  with gr.Row():
51
  file_input = gr.File(label="Upload CSV File", file_count="single", file_types=[".csv"])
52
+
53
  with gr.Row():
54
  clean_button = gr.Button("Start Cleaning")
55
+
56
  with gr.Row():
57
  progress_bar = gr.Progress()
58
+
59
  with gr.Row():
60
  cleaned_file_output = gr.File(label="Cleaned CSV", visible=True)
61
+
62
  with gr.Row():
63
+ output_gallery = gr.Gallery(
64
+ label="Visualization Results",
65
+ show_label=True,
66
+ elem_id="gallery",
67
+ columns=[2],
68
+ rows=[2],
69
+ object_fit="contain",
70
+ height="auto",
71
+ visible=False # Initially set to invisible
72
+ )
73
+
74
  def process_and_show_results(file):
75
  cleaned_csv_path, image_files = clean_and_visualize(file, progress=progress_bar)
76
+ return (
77
+ cleaned_csv_path,
78
+ gr.Gallery(visible=True, value=image_files) # Make gallery visible and update its content
79
+ )
80
+
81
  clean_button.click(
82
  fn=process_and_show_results,
83
  inputs=file_input,
84
  outputs=[cleaned_file_output, output_gallery]
85
  )
86
+
87
  app.launch()
88
 
89
  if __name__ == "__main__":