khushalcodiste commited on
Commit
39c7e26
·
1 Parent(s): eb84c1f

feat: First comit

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -388,14 +388,20 @@ async def predict_file(file: UploadFile = File(...), steps: int = 10) -> Predict
388
  try:
389
  df = pd.read_csv(io.BytesIO(content))
390
  except Exception:
391
- # If CSV fails, try Excel
392
- try:
393
- df = pd.read_excel(io.BytesIO(content))
394
- except Exception as exc2:
 
 
 
 
 
 
395
  raise HTTPException(
396
  status_code=400,
397
- detail=f"could not read file as CSV or Excel: {exc2}"
398
- ) from exc2
399
  except Exception as exc:
400
  raise HTTPException(status_code=400, detail=f"could not read file: {exc}") from exc
401
 
 
388
  try:
389
  df = pd.read_csv(io.BytesIO(content))
390
  except Exception:
391
+ # If CSV fails, try Excel with multiple engines
392
+ excel_read_error = None
393
+ for engine in ("openpyxl", "xlrd"):
394
+ try:
395
+ df = pd.read_excel(io.BytesIO(content), engine=engine)
396
+ break
397
+ except Exception as exc_excel:
398
+ excel_read_error = exc_excel
399
+ df = None
400
+ if df is None:
401
  raise HTTPException(
402
  status_code=400,
403
+ detail=f"could not read file as CSV or Excel: {excel_read_error}"
404
+ ) from excel_read_error
405
  except Exception as exc:
406
  raise HTTPException(status_code=400, detail=f"could not read file: {exc}") from exc
407