sujithrajaR commited on
Commit
4c0c68a
Β·
verified Β·
1 Parent(s): 82845cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -32
app.py CHANGED
@@ -62,7 +62,8 @@ def clean_column(column, null_action, case_action, fill_value):
62
  df_global[column].fillna(method="ffill", inplace=True)
63
  elif null_action == "Backward Fill (bfill)":
64
  df_global[column].fillna(method="bfill", inplace=True)
65
- elif null_action == "Remove Nulls":
 
66
  df_global = df_global[df_global[column].notna()]
67
 
68
  # Case conversion
@@ -147,32 +148,25 @@ def plot_column(column, plot_type):
147
  return None, "❌ Column not found or dataset not loaded!"
148
 
149
  plt.figure(figsize=(6,4))
150
- try:
151
- # Convert column to numeric if possible for hist/kde/box plots
152
- if pd.api.types.is_numeric_dtype(df_global[column]) == False:
153
- df_global[column] = pd.to_numeric(df_global[column], errors='coerce')
154
-
155
- if plot_type == "Histogram":
156
- sns.histplot(df_global[column].dropna(), kde=True)
157
- elif plot_type == "Boxplot":
158
- sns.boxplot(x=df_global[column].dropna())
159
- elif plot_type == "Bar Plot":
160
- if pd.api.types.is_numeric_dtype(df_global[column]):
161
- sns.barplot(x=df_global.index, y=df_global[column])
162
- else:
163
- sns.countplot(x=df_global[column])
164
- elif plot_type == "Scatter Plot":
165
- num_cols = df_global.select_dtypes(include=[np.number]).columns
166
- if len(num_cols) >= 2:
167
- sns.scatterplot(x=df_global[num_cols[0]], y=df_global[num_cols[1]])
168
- else:
169
- return None, "❌ Not enough numeric columns for scatter plot"
170
- plt.tight_layout()
171
- plt.savefig("temp_plot.png")
172
- plt.close()
173
- return "temp_plot.png", f"βœ… {plot_type} generated for column '{column}'"
174
- except Exception as e:
175
- return None, f"❌ Error in plotting: {str(e)}"
176
 
177
  # --------------------
178
  # Gradio UI
@@ -181,10 +175,12 @@ with gr.Blocks(title=APP_TITLE) as demo:
181
  gr.Markdown(f"# {APP_TITLE}")
182
  gr.Markdown("Upload your dataset, clean it, and visualize columns dynamically.")
183
 
 
184
  with gr.Row():
185
  file_input = gr.File(label="πŸ“‚ Upload Dataset", file_types=[".csv", ".xlsx", ".json"])
186
  status = gr.Textbox(label="Status", interactive=False)
187
 
 
188
  with gr.Row():
189
  trim_spaces = gr.Checkbox(label="Trim whitespace", value=False)
190
  normalize_case = gr.Dropdown(["Keep case", "lower()", "UPPER()", "Title Case"], value="Keep case")
@@ -200,7 +196,7 @@ with gr.Blocks(title=APP_TITLE) as demo:
200
  full_clean_btn = gr.Button("✨ Apply Full Cleaning")
201
 
202
  # Column-level cleaning
203
- column_dropdown = gr.Dropdown(label="πŸ“Š Select Column", choices=[], interactive=True)
204
  null_action = gr.Dropdown(["Remove Nulls", "Fill with Mean", "Fill with Median", "Fill with Mode",
205
  "Fill with Constant", "Forward Fill (ffill)", "Backward Fill (bfill)"],
206
  label="Handle Null Values")
@@ -223,7 +219,4 @@ with gr.Blocks(title=APP_TITLE) as demo:
223
  clean_column_btn.click(clean_column, inputs=[column_dropdown, null_action, case_action, fill_value], outputs=[status, output_table])
224
  plot_btn.click(plot_column, inputs=[column_dropdown, plot_type], outputs=[plot_output, status])
225
 
226
- # --------------------
227
- # Launch Gradio app
228
- # --------------------
229
- demo.launch(server_name="0.0.0.0", server_port=7860, share=True)
 
62
  df_global[column].fillna(method="ffill", inplace=True)
63
  elif null_action == "Backward Fill (bfill)":
64
  df_global[column].fillna(method="bfill", inplace=True)
65
+
66
+ if null_action == "Remove Nulls":
67
  df_global = df_global[df_global[column].notna()]
68
 
69
  # Case conversion
 
148
  return None, "❌ Column not found or dataset not loaded!"
149
 
150
  plt.figure(figsize=(6,4))
151
+ if plot_type == "Histogram":
152
+ sns.histplot(df_global[column].dropna(), kde=True)
153
+ elif plot_type == "Boxplot":
154
+ sns.boxplot(x=df_global[column])
155
+ elif plot_type == "Bar Plot":
156
+ if pd.api.types.is_numeric_dtype(df_global[column]):
157
+ sns.barplot(x=df_global.index, y=df_global[column])
158
+ else:
159
+ sns.countplot(x=df_global[column])
160
+ elif plot_type == "Scatter Plot":
161
+ num_cols = df_global.select_dtypes(include=[np.number]).columns
162
+ if len(num_cols) >= 2:
163
+ sns.scatterplot(x=df_global[num_cols[0]], y=df_global[num_cols[1]])
164
+ else:
165
+ return None, "❌ Not enough numeric columns for scatter plot"
166
+ plt.tight_layout()
167
+ plt.savefig("temp_plot.png")
168
+ plt.close()
169
+ return "temp_plot.png", f"βœ… {plot_type} generated for column '{column}'"
 
 
 
 
 
 
 
170
 
171
  # --------------------
172
  # Gradio UI
 
175
  gr.Markdown(f"# {APP_TITLE}")
176
  gr.Markdown("Upload your dataset, clean it, and visualize columns dynamically.")
177
 
178
+ # File input
179
  with gr.Row():
180
  file_input = gr.File(label="πŸ“‚ Upload Dataset", file_types=[".csv", ".xlsx", ".json"])
181
  status = gr.Textbox(label="Status", interactive=False)
182
 
183
+ # Full cleaning options
184
  with gr.Row():
185
  trim_spaces = gr.Checkbox(label="Trim whitespace", value=False)
186
  normalize_case = gr.Dropdown(["Keep case", "lower()", "UPPER()", "Title Case"], value="Keep case")
 
196
  full_clean_btn = gr.Button("✨ Apply Full Cleaning")
197
 
198
  # Column-level cleaning
199
+ column_dropdown = gr.Dropdown(label="πŸ“Š Select Column", choices=[], interactive=True, allow_custom_value=True)
200
  null_action = gr.Dropdown(["Remove Nulls", "Fill with Mean", "Fill with Median", "Fill with Mode",
201
  "Fill with Constant", "Forward Fill (ffill)", "Backward Fill (bfill)"],
202
  label="Handle Null Values")
 
219
  clean_column_btn.click(clean_column, inputs=[column_dropdown, null_action, case_action, fill_value], outputs=[status, output_table])
220
  plot_btn.click(plot_column, inputs=[column_dropdown, plot_type], outputs=[plot_output, status])
221
 
222
+ demo.launch()