entropy25 commited on
Commit
e891cb3
·
verified ·
1 Parent(s): e595151

Update data_handler.py

Browse files
Files changed (1) hide show
  1. data_handler.py +19 -2
data_handler.py CHANGED
@@ -5,7 +5,6 @@ import warnings
5
  from typing import Dict, List, Any
6
  warnings.filterwarnings('ignore')
7
 
8
- # Enhanced data processing functions with better error handling
9
  @st.cache_data
10
  def load_csv_with_encoding(file_content: bytes, filename: str) -> pd.DataFrame:
11
  """Load CSV with automatic encoding detection and enhanced error handling"""
@@ -272,4 +271,22 @@ def calculate_data_quality_score(df: pd.DataFrame) -> Dict[str, Any]:
272
  'validity': 0,
273
  'overall': 0,
274
  'grade': 'Unknown'
275
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  from typing import Dict, List, Any
6
  warnings.filterwarnings('ignore')
7
 
 
8
  @st.cache_data
9
  def load_csv_with_encoding(file_content: bytes, filename: str) -> pd.DataFrame:
10
  """Load CSV with automatic encoding detection and enhanced error handling"""
 
271
  'validity': 0,
272
  'overall': 0,
273
  'grade': 'Unknown'
274
+ }
275
+
276
+ def load_data(uploaded_file):
277
+ """Main function to load data - for compatibility"""
278
+ try:
279
+ file_extension = uploaded_file.name.split('.')[-1].lower()
280
+ file_content = uploaded_file.getvalue()
281
+
282
+ if file_extension == 'csv':
283
+ return load_csv_with_encoding(file_content, uploaded_file.name)
284
+ elif file_extension in ['xlsx', 'xls']:
285
+ return load_excel_file(file_content, uploaded_file.name)
286
+ else:
287
+ st.error("Unsupported file format")
288
+ return None
289
+
290
+ except Exception as e:
291
+ st.error(f"Error loading file: {str(e)}")
292
+ return None