GitHub Actions commited on
Commit
f6e58dd
·
1 Parent(s): 220e861

Sync API from main repo

Browse files
Files changed (1) hide show
  1. fast.py +9 -4
fast.py CHANGED
@@ -37,14 +37,19 @@ async def predict(model_name: str, filepath_csv: UploadFile = File(...)):
37
 
38
  # if model in model_path, load it, otherwise download it from HF
39
  if model_name not in model_cache:
 
 
40
  try:
41
  if not model_path.exists():
42
- model_path = hf_hub_download(repo_id=HF_REPO_ID, filename=f"{model_name}")
43
- encoder_path = hf_hub_download(repo_id=HF_REPO_ID, filename=f"{encoder_name}")
44
- model_cache[model_name] = load_model_by_type(model_path)
 
 
45
  encoder_cache[model_name] = encoder_path
46
  except Exception as e:
47
- raise HTTPException(status_code=404, detail=f"Model {model_name} not found")
 
48
  model = app.state.model = model_cache[model_name]
49
 
50
  # Read the uploaded CSV file
 
37
 
38
  # if model in model_path, load it, otherwise download it from HF
39
  if model_name not in model_cache:
40
+ print("model_name", model_name)
41
+ print("model_path", model_path)
42
  try:
43
  if not model_path.exists():
44
+ # Convert downloaded paths to Path objects
45
+ model_path = Path(hf_hub_download(repo_id=HF_REPO_ID, filename=f"{model_name}"))
46
+ encoder_path = Path(hf_hub_download(repo_id=HF_REPO_ID, filename=f"{encoder_name}"))
47
+ print("model_path", model_path)
48
+ model_cache[model_name] = load_model_by_type(model_path) # Ensure string path for loading
49
  encoder_cache[model_name] = encoder_path
50
  except Exception as e:
51
+ print(f"Error loading model: {str(e)}") # Add debug print
52
+ raise HTTPException(status_code=404, detail=f"Model {model_name} not found: {str(e)}")
53
  model = app.state.model = model_cache[model_name]
54
 
55
  # Read the uploaded CSV file