gaur3009 commited on
Commit
ac81731
·
verified ·
1 Parent(s): 8fa38d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -3
app.py CHANGED
@@ -84,15 +84,32 @@ def plot_feature_importance(importance):
84
  plt.close()
85
  return buf
86
 
87
- # Main analysis function
88
  def analyze_file(file):
89
  try:
90
  # Step 1: Read file
91
  df = read_file(file)
92
 
 
 
 
 
 
 
 
 
 
93
  # Step 2: Clean data
94
  df_cleaned = clean_data(df)
95
 
 
 
 
 
 
 
 
 
 
96
  # Step 3: Generate summary statistics
97
  summary = generate_summary(df_cleaned)
98
 
@@ -110,8 +127,22 @@ def analyze_file(file):
110
  importance.head(10), # Top 10 important features
111
  importance_plot_buf,
112
  )
 
 
 
 
 
 
 
 
113
  except Exception as e:
114
- return str(e)
 
 
 
 
 
 
115
 
116
  # Gradio Interface
117
  def gradio_interface():
@@ -139,4 +170,4 @@ def gradio_interface():
139
 
140
  # Launch the Gradio interface
141
  interface = gradio_interface()
142
- interface.launch(debug=True)
 
84
  plt.close()
85
  return buf
86
 
 
87
  def analyze_file(file):
88
  try:
89
  # Step 1: Read file
90
  df = read_file(file)
91
 
92
+ # Check if the dataframe is empty
93
+ if df.empty:
94
+ return (
95
+ "The uploaded file is empty or has no valid data.",
96
+ None,
97
+ None,
98
+ None,
99
+ )
100
+
101
  # Step 2: Clean data
102
  df_cleaned = clean_data(df)
103
 
104
+ # Check if the cleaned dataframe is still empty
105
+ if df_cleaned.empty:
106
+ return (
107
+ "The dataset contains no valid data after cleaning.",
108
+ None,
109
+ None,
110
+ None,
111
+ )
112
+
113
  # Step 3: Generate summary statistics
114
  summary = generate_summary(df_cleaned)
115
 
 
127
  importance.head(10), # Top 10 important features
128
  importance_plot_buf,
129
  )
130
+ except ValueError as ve:
131
+ # Handle file format issues or parsing errors
132
+ return (
133
+ f"ValueError: {str(ve)}",
134
+ None,
135
+ None,
136
+ None,
137
+ )
138
  except Exception as e:
139
+ # Catch any other unforeseen issues
140
+ return (
141
+ f"An unexpected error occurred: {str(e)}",
142
+ None,
143
+ None,
144
+ None,
145
+ )
146
 
147
  # Gradio Interface
148
  def gradio_interface():
 
170
 
171
  # Launch the Gradio interface
172
  interface = gradio_interface()
173
+ interface.launch(debug=True)