andreamena commited on
Commit
4cefe27
·
verified ·
1 Parent(s): e0b249d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -84,22 +84,24 @@ def batch_predict(app_choice, file_obj):
84
  except UnicodeDecodeError:
85
  df = pd.read_csv(filename, encoding='latin1', on_bad_lines='skip')
86
  elif filename.endswith(('.xls', '.xlsx')):
87
- df = pd.read_excel(filename)
 
88
  else:
89
  err_path = tempfile.NamedTemporaryFile(delete=False, suffix=".txt").name
90
- with open(err_path, "w") as f: f.write("Unsupported file format. Please upload a .csv or .xlsx file.")
91
  return None, err_path
92
 
93
- # Find the column containing SMILES (case-insensitive)
94
- s_col = next((c for c in df.columns if 'smiles' in c.lower()), None)
 
95
  if not s_col:
96
  err_path = tempfile.NamedTemporaryFile(delete=False, suffix=".txt").name
97
- with open(err_path, "w") as f: f.write("Error: File must have a 'SMILES' column.")
 
98
  return None, err_path
99
 
100
  results = []
101
  for s in df[s_col]:
102
- # This utility handles both *CC* (p-SMILES) and CCC (SMILES)
103
  feats = get_mff_features(str(s))
104
  if feats is not None:
105
  if app_choice == "Structural (Strength)":
 
84
  except UnicodeDecodeError:
85
  df = pd.read_csv(filename, encoding='latin1', on_bad_lines='skip')
86
  elif filename.endswith(('.xls', '.xlsx')):
87
+ # Added engine='openpyxl' for better compatibility
88
+ df = pd.read_excel(filename, engine='openpyxl')
89
  else:
90
  err_path = tempfile.NamedTemporaryFile(delete=False, suffix=".txt").name
91
+ with open(err_path, "w") as f: f.write("Unsupported format. Please upload .csv or .xlsx")
92
  return None, err_path
93
 
94
+ # MODIFIED: Look for 'smile' OR 'smiles' (handles your SMILES.xlsx)
95
+ s_col = next((c for c in df.columns if 'smile' in c.lower()), None)
96
+
97
  if not s_col:
98
  err_path = tempfile.NamedTemporaryFile(delete=False, suffix=".txt").name
99
+ with open(err_path, "w") as f:
100
+ f.write(f"Error: Could not find SMILES column. Found: {df.columns.tolist()}")
101
  return None, err_path
102
 
103
  results = []
104
  for s in df[s_col]:
 
105
  feats = get_mff_features(str(s))
106
  if feats is not None:
107
  if app_choice == "Structural (Strength)":