pavanmutha commited on
Commit
cd69066
·
verified ·
1 Parent(s): c1b291b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -191,7 +191,12 @@ def train_model(_):
191
 
192
  def prepare_data():
193
  """Prepares the dataset by splitting into X and y, and returns training and test sets."""
194
- global X_train, X_test, y_train, y_test
 
 
 
 
 
195
  target = df_global.columns[-1]
196
  X = df_global.drop(target, axis=1)
197
  y = df_global[target]
@@ -202,8 +207,13 @@ def prepare_data():
202
  X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
203
  return X_train, X_test, y_train, y_test
204
 
205
- # Prepare the data before the optimization process
206
- X_train, X_test, y_train, y_test = prepare_data()
 
 
 
 
 
207
 
208
  def objective(trial):
209
  params = {
 
191
 
192
  def prepare_data():
193
  """Prepares the dataset by splitting into X and y, and returns training and test sets."""
194
+ global df_global, X_train, X_test, y_train, y_test
195
+
196
+ # Check if df_global is None, which means no file has been uploaded yet
197
+ if df_global is None:
198
+ raise ValueError("DataFrame is None. Please upload a dataset first.")
199
+
200
  target = df_global.columns[-1]
201
  X = df_global.drop(target, axis=1)
202
  y = df_global[target]
 
207
  X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
208
  return X_train, X_test, y_train, y_test
209
 
210
+ # Prepare the data before the optimization process, with a check for df_global
211
+ try:
212
+ X_train, X_test, y_train, y_test = prepare_data()
213
+ except ValueError as e:
214
+ print(e) # You can log this or return it as a message in the UI
215
+ # Handle the error by returning or setting defaults as needed.
216
+
217
 
218
  def objective(trial):
219
  params = {