AbdullahImran commited on
Commit
3dac46f
·
verified ·
1 Parent(s): c7e7611

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -22,23 +22,31 @@ expected_features = xgb_clf.get_booster().feature_names
22
  # Set matplotlib style for dark theme compatibility
23
  plt.style.use('dark_background')
24
 
25
- def process_csv_file(file):
26
- """Process uploaded CSV file and return DataFrame"""
27
  if file is None:
28
  return None
29
  try:
30
- df = pd.read_csv(file.name)
 
 
 
 
 
 
31
  return df
32
  except Exception as e:
33
- gr.Warning(f"Error reading CSV file: {str(e)}")
34
  return None
35
 
 
36
  def run_all_models(file):
37
  """Run all three models on the uploaded CSV file"""
38
  if file is None:
39
  return "Please upload a CSV file", None, None, None, None, None
40
 
41
- df = process_csv_file(file)
 
42
  if df is None:
43
  return "Error processing file", None, None, None, None, None
44
 
 
22
  # Set matplotlib style for dark theme compatibility
23
  plt.style.use('dark_background')
24
 
25
+ def process_file(file):
26
+ """Process uploaded file (.csv, .xlsx, .xls) and return DataFrame"""
27
  if file is None:
28
  return None
29
  try:
30
+ if file.name.endswith('.csv'):
31
+ df = pd.read_csv(file.name)
32
+ elif file.name.endswith(('.xls', '.xlsx')):
33
+ df = pd.read_excel(file.name, engine='openpyxl') # you can also try 'xlrd' for .xls
34
+ else:
35
+ gr.Warning("Unsupported file format. Please upload a .csv, .xls, or .xlsx file.")
36
+ return None
37
  return df
38
  except Exception as e:
39
+ gr.Warning(f"Error reading file: {str(e)}")
40
  return None
41
 
42
+
43
  def run_all_models(file):
44
  """Run all three models on the uploaded CSV file"""
45
  if file is None:
46
  return "Please upload a CSV file", None, None, None, None, None
47
 
48
+ df = process_file(file)
49
+
50
  if df is None:
51
  return "Error processing file", None, None, None, None, None
52