ArabovMK commited on
Commit
edc0b5f
·
1 Parent(s): 5dc70c5

Resolve value unpacking error in preprocessing module.

Browse files
Files changed (1) hide show
  1. app.py +21 -21
app.py CHANGED
@@ -17,22 +17,22 @@ import shutil
17
  # PATH CHECKING UTILITIES
18
  # ============================================
19
  def check_preprocessing_status():
20
- """Проверяет наличие и заполненность папки с предобработанными данными"""
21
  preprocessing_path = current_dir / "src" / "enhanced_preprocessing_results" / "processed_data"
22
 
23
- # Проверяем существование папки
24
  if not preprocessing_path.exists():
25
- return False, "Папка с предобработанными данными не найдена"
26
 
27
- # Проверяем, не пуста ли папка
28
  try:
29
  files = list(preprocessing_path.glob("*"))
30
  files = [f for f in files if f.is_file()]
31
 
32
  if len(files) == 0:
33
- return False, "Папка с предобработанными данными пуста"
34
 
35
- # Пробуем загрузить данные, если они есть
36
  try:
37
  for file in files:
38
  if file.suffix.lower() in ['.csv', '.parquet']:
@@ -43,14 +43,14 @@ def check_preprocessing_status():
43
 
44
  if not data.empty:
45
  fixed_data = fix_dataframe_for_streamlit(data)
46
- return True, "Предобработка выполнена", fixed_data
47
  except:
48
  pass
49
 
50
- return True, "Предобработка выполнена", None
51
 
52
  except Exception as e:
53
- return False, f"Ошибка при проверке папки: {str(e)}", None
54
 
55
  # Configure paths
56
  current_dir = Path(__file__).parent
@@ -295,13 +295,13 @@ def normalize_ml_results(results):
295
  # DATA LOADING FUNCTIONS
296
  # ============================================
297
  def load_data_from_preprocessing():
298
- """Загружает данные из папки предобработки"""
299
  preprocessing_ready, preprocessing_message, preprocessed_data = check_preprocessing_status()
300
 
301
  if preprocessing_ready and preprocessed_data is not None:
302
  return preprocessed_data
303
  elif preprocessing_ready:
304
- # Папка есть, но данные не загрузились - пробуем загрузить вручную
305
  preprocessing_path = current_dir / "src" / "enhanced_preprocessing_results" / "processed_data"
306
  files = list(preprocessing_path.glob("*"))
307
 
@@ -321,20 +321,20 @@ def load_data_from_preprocessing():
321
  fixed_data = fix_dataframe_for_streamlit(data)
322
  return fixed_data
323
  except Exception as e:
324
- st.warning(f"⚠️ Не удалось загрузить файл {file.name}: {str(e)}")
325
 
326
  return None
327
 
328
  def get_current_data():
329
- """Получает текущие данные из всех возможных источников"""
330
- # 1. Проверяем session_state
331
  if st.session_state.preprocessed_data is not None:
332
  return st.session_state.preprocessed_data
333
 
334
- # 2. Проверяем папку предобработки
335
  data = load_data_from_preprocessing()
336
  if data is not None:
337
- # Сохраняем в session_state для будущего использования
338
  st.session_state.preprocessed_data = data
339
  return data
340
 
@@ -801,7 +801,7 @@ def run_ml_pipeline():
801
  """Runs the ML module with enhanced error handling"""
802
  st.title("🤖 ML Pipeline PRO - Machine Learning")
803
 
804
- # Получаем данные из всех возможных источников
805
  data = get_current_data()
806
 
807
  if data is None:
@@ -816,7 +816,7 @@ def run_ml_pipeline():
816
  st.rerun()
817
  return
818
 
819
- # Проверяем, что данные валидны
820
  if not isinstance(data, pd.DataFrame) or data.empty:
821
  st.error("❌ Invalid data format! Please load valid data.")
822
  if st.button("← Go to Data Preprocessing", type="primary", width='stretch'):
@@ -899,7 +899,7 @@ def run_ml_pipeline():
899
 
900
  module.set_results_handler(ml_results_handler)
901
 
902
- # Передаем данные в модуль
903
  module.data = data
904
  module.target_column = target_col
905
 
@@ -956,7 +956,7 @@ def show_alternative_ml(data=None, target_col=None):
956
  st.markdown("---")
957
  st.markdown("### 🤖 Simplified ML Training")
958
 
959
- # Если данные не переданы, пытаемся получить их
960
  if data is None:
961
  data = get_current_data()
962
 
@@ -967,7 +967,7 @@ def show_alternative_ml(data=None, target_col=None):
967
  st.rerun()
968
  return
969
 
970
- # Если target_col не передан, запрашиваем его
971
  if target_col is None:
972
  numeric_cols = data.select_dtypes(include=[np.number]).columns.tolist()
973
  if not numeric_cols:
 
17
  # PATH CHECKING UTILITIES
18
  # ============================================
19
  def check_preprocessing_status():
20
+ """Check the existence and content of the preprocessed data folder"""
21
  preprocessing_path = current_dir / "src" / "enhanced_preprocessing_results" / "processed_data"
22
 
23
+ # Check if folder exists
24
  if not preprocessing_path.exists():
25
+ return False, "Preprocessed data folder not found", None
26
 
27
+ # Check if folder is not empty
28
  try:
29
  files = list(preprocessing_path.glob("*"))
30
  files = [f for f in files if f.is_file()]
31
 
32
  if len(files) == 0:
33
+ return False, "Preprocessed data folder is empty", None
34
 
35
+ # Try to load data if available
36
  try:
37
  for file in files:
38
  if file.suffix.lower() in ['.csv', '.parquet']:
 
43
 
44
  if not data.empty:
45
  fixed_data = fix_dataframe_for_streamlit(data)
46
+ return True, "Preprocessing completed", fixed_data
47
  except:
48
  pass
49
 
50
+ return True, "Preprocessing completed", None
51
 
52
  except Exception as e:
53
+ return False, f"Error checking folder: {str(e)}", None
54
 
55
  # Configure paths
56
  current_dir = Path(__file__).parent
 
295
  # DATA LOADING FUNCTIONS
296
  # ============================================
297
  def load_data_from_preprocessing():
298
+ """Load data from preprocessing folder"""
299
  preprocessing_ready, preprocessing_message, preprocessed_data = check_preprocessing_status()
300
 
301
  if preprocessing_ready and preprocessed_data is not None:
302
  return preprocessed_data
303
  elif preprocessing_ready:
304
+ # Folder exists but data didn't load - try manual loading
305
  preprocessing_path = current_dir / "src" / "enhanced_preprocessing_results" / "processed_data"
306
  files = list(preprocessing_path.glob("*"))
307
 
 
321
  fixed_data = fix_dataframe_for_streamlit(data)
322
  return fixed_data
323
  except Exception as e:
324
+ st.warning(f"⚠️ Could not load file {file.name}: {str(e)}")
325
 
326
  return None
327
 
328
  def get_current_data():
329
+ """Get current data from all possible sources"""
330
+ # 1. Check session_state
331
  if st.session_state.preprocessed_data is not None:
332
  return st.session_state.preprocessed_data
333
 
334
+ # 2. Check preprocessing folder
335
  data = load_data_from_preprocessing()
336
  if data is not None:
337
+ # Save to session_state for future use
338
  st.session_state.preprocessed_data = data
339
  return data
340
 
 
801
  """Runs the ML module with enhanced error handling"""
802
  st.title("🤖 ML Pipeline PRO - Machine Learning")
803
 
804
+ # Get data from all possible sources
805
  data = get_current_data()
806
 
807
  if data is None:
 
816
  st.rerun()
817
  return
818
 
819
+ # Check that data is valid
820
  if not isinstance(data, pd.DataFrame) or data.empty:
821
  st.error("❌ Invalid data format! Please load valid data.")
822
  if st.button("← Go to Data Preprocessing", type="primary", width='stretch'):
 
899
 
900
  module.set_results_handler(ml_results_handler)
901
 
902
+ # Pass data to the module
903
  module.data = data
904
  module.target_column = target_col
905
 
 
956
  st.markdown("---")
957
  st.markdown("### 🤖 Simplified ML Training")
958
 
959
+ # If data not passed, try to get it
960
  if data is None:
961
  data = get_current_data()
962
 
 
967
  st.rerun()
968
  return
969
 
970
+ # If target_col not passed, request it
971
  if target_col is None:
972
  numeric_cols = data.select_dtypes(include=[np.number]).columns.tolist()
973
  if not numeric_cols: