pycaret
pycaret copied to clipboard
[BUG]: create_api errors!
pycaret version checks
-
[X] I have checked that this issue has not already been reported here.
-
[X] I have confirmed this bug exists on the latest version of pycaret.
-
[X] I have confirmed this bug exists on the master branch of pycaret (pip install -U git+https://github.com/pycaret/pycaret.git@master).
Issue Description
try create api and receive error IndentationError: unexpected indent
Reproducible Example
create_api(final_model, 'final_model_api')
!python final_model_api.py
Expected Behavior
no errors
Actual Results
File "C:\...\final_model_api.py", line 2
import pandas as pd
IndentationError: unexpected indent
Installed Versions
After edit file final_model_api.py, remove identation and run notebook cell to run file, i receive new error: Traceback (most recent call last):
File "C:...\final_model_api.py", line 3, in
Yes, I'm facing the same issuue
@ngupta23 create_api maybe work on pycaret 2.3.x, however pycaret 3.x code as changed but create_api command needs changes too. Can you have a look on that?
I found some issues that need to be fixed:
- indentation in code of created file by create_api (indentation should be removed)
- Line 3 "from pycaret. MLUsecase.CLASSIFICATION import load_model, predict_model" .shoud be changed by "
from pycaret.classification import load_model, predict_model
" ? - Possible problem in windows. Use of !python filename.py (created by create_api) maybe not work. I had to open a tab manually. I think it should be automatic, that is, open a new tab automatically with url: http://127.0.0.1:8000/docs .
I think you already have an initial idea of how to solve the problem.
Well i do all manually but is in my laptop, can you make this changes in pycaret?
thanks
I tried to test the create_app command and it also doesn't work in pycaret 3. It doesn't assume the features that pycaret itself created, like the year, month, day extracted from date_time feature...
Reproduced in August 15th meeting. Fix needed in these 2 places
- Indent
- correct import per latest library structure
Reproduced in August 15th meeting...where is the meeting? Live on Youtube?
Reproduced in August 15th meeting...where is the meeting? Live on Youtube?
The core developers try to meet once a week to discuss next steps, etc.
Per August 29th meeting, reassigned to @tvdboom.
@tvdboom I have tested this after the fix this morning, the indent and import issue is fixed however a new thing I noticed:
lr = create_model('lr')
create_api(lr, 'my_lr_api')
!python my_lr_api.py
(pycaret-dev) C:\Users\owner\pycaret>python my_lr_api.py
Transformation Pipeline and Model Successfully Loaded
Traceback (most recent call last):
File "my_lr_api.py", line 17, in
Line 17 of api failing. The API generated:
import pandas as pd
from pycaret.classification import load_model, predict_model
from fastapi import FastAPI
import uvicorn
from pydantic import create_model
# Create the app
app = FastAPI()
# Load trained Pipeline
model = load_model("my_lr_api")
# Create input/output pydantic models
pydanticinputmodel=create_model("my_lr_api_input", **{'Id': 585, 'WeekofPurchase': 264, 'StoreID': 7, 'PriceCH': 1.8600000143051147, 'PriceMM': 2.130000114440918, 'DiscCH': 0.3700000047683716, 'DiscMM': 0.0, 'SpecialCH': 1, 'SpecialMM': 0, 'LoyalCH': 0.8361600041389465, 'SalePriceMM': 2.130000114440918, 'SalePriceCH': 1.4900000095367432, 'PriceDiff': 0.6399999856948853, 'Store7': 'Yes', 'PctDiscMM': 0.0, 'PctDiscCH': 0.19892500340938568, 'ListPriceDiff': 0.27000001072883606, 'STORE': 0})
pydanticoutputmodel=create_model("my_lr_api_output", **{targetname: self.y.iloc[0]})
# Define predict function
@app.post("/predict", response_model=pydanticoutputmodel)
def predict(datainput:pydanticinputmodel):
data = pd.DataFrame([datainput.dict()])
predictions = predict_model(model, data=data)
return {"Purchase_prediction": predictions["prediction_label"][0]}
if __name__ == "__main__":
uvicorn.run(app, host="127.0.0.1", port=8000)
I fixed this error but my app is not launching correctly. @moezali1 can you try using the change_engine_param_name repo? Not sure what the error is now
@tvdboom Just did. The exact same error.
@moezali1 That can't be because that code is no longer there. Are you using the change_engine_param_name repo?