reab5555 commited on
Commit
1957a2b
1 Parent(s): ac9fbc9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +92 -92
app.py CHANGED
@@ -1,93 +1,93 @@
1
- import gradio as gr
2
- import pandas as pd
3
- from clean import clean_data
4
- from report import create_full_report, REPORT_DIR
5
- import os
6
- import tempfile
7
-
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,
29
- cleaned_df,
30
- nonconforming_cells_before,
31
- process_times,
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")
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
- download_button = gr.Button("Download Cleaned CSV", visible=False)
61
- cleaned_file_output = gr.File(label="Cleaned CSV", visible=False)
62
-
63
- with gr.Row():
64
- output_gallery = gr.Gallery(label="Visualization Results", show_label=True, elem_id="gallery", columns=[2],
65
- rows=[2], object_fit="contain", height="auto")
66
-
67
- def process_and_show_download(file):
68
- cleaned_csv_path, image_files = clean_and_visualize(file, progress=progress_bar)
69
- return (
70
- gr.Button.update(visible=True),
71
- gr.File.update(value=cleaned_csv_path, visible=True),
72
- image_files
73
- )
74
-
75
- clean_button.click(
76
- fn=process_and_show_download,
77
- inputs=file_input,
78
- outputs=[download_button, cleaned_file_output, output_gallery]
79
- )
80
-
81
- def trigger_download():
82
- return gr.File.update(visible=True)
83
-
84
- download_button.click(
85
- fn=trigger_download,
86
- inputs=[],
87
- outputs=[cleaned_file_output]
88
- )
89
-
90
- app.launch()
91
-
92
- if __name__ == "__main__":
93
  launch_app()
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ from clean import clean_data
4
+ from report import create_full_report, REPORT_DIR
5
+ import os
6
+ import tempfile
7
+
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,
29
+ cleaned_df,
30
+ nonconforming_cells_before,
31
+ process_times,
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")
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
+ download_button = gr.Button("Download Cleaned CSV", visible=False)
61
+ cleaned_file_output = gr.File(label="Cleaned CSV", visible=False)
62
+
63
+ with gr.Row():
64
+ output_gallery = gr.Gallery(label="Visualization Results", show_label=True, elem_id="gallery", columns=[2],
65
+ rows=[2], object_fit="contain", height="auto")
66
+
67
+ def process_and_show_download(file):
68
+ cleaned_csv_path, image_files = clean_and_visualize(file, progress=progress_bar)
69
+ return (
70
+ gr.Button.update(visible=True),
71
+ gr.File.update(value=cleaned_csv_path, visible=True),
72
+ image_files
73
+ )
74
+
75
+ clean_button.click(
76
+ fn=process_and_show_download,
77
+ inputs=file_input,
78
+ outputs=[download_button, cleaned_file_output, output_gallery]
79
+ )
80
+
81
+ def trigger_download():
82
+ return gr.File.update(visible=True)
83
+
84
+ download_button.click(
85
+ fn=trigger_download,
86
+ inputs=[],
87
+ outputs=[cleaned_file_output]
88
+ )
89
+
90
+ app.launch()
91
+
92
+ if __name__ == "__main__":
93
  launch_app()