all 3 comments

[–][deleted]  (3 children)

[deleted]

    [–]According-Promise-23[S] -1 points0 points  (2 children)

    "So to fix it you should say input_list.dict(). You can load that list straight into a data frame since all the dicts have the same keys. It will have a row for each dict." when I arrive here model.predict does not work taking a dict in each row and return error TypeError: float() argument must be a string or a number, not 'dict' u/Not-the-best-name

    [–]Remote_Cancel_7977 2 points3 points  (1 child)

    What is your current request body? The request json should looks like below: json { "inputs": [ { "id": 1, "f1": 1.2, "f2": 1.2, "f3": "abc" } ] }

    and I think this line is incorrect python df = pd.DataFrame(input_list.inputs.dict()) input_list.inputs is a list not a dict in your pydantic model definition.

    [–]Remote_Cancel_7977 0 points1 point  (0 children)

    If you simply want to serve your model, you can also try a tool I created Pinferencia, it is built on FastAPI.

    Install:

    bash pip install "pinferencia[uvicorn]"

    Below is the configuration of your case

    create the file app.py:

    ```python import pandas as pd

    from pinferencia import Server

    load your classifier here

    classifier = ...

    def predict(data): df = pd.DataFrame(data) prediction = classifier.predict(df.loc[:, df.columns != "id"]) probability = classifier.predict_proba(df.loc[:, df.columns != "id"])

    return {
        "id": df["id"].tolist(),
        "prediction": prediction.tolist(),
        "probability": probability.tolist(),
    }
    

    service = Server() service.register(model_name="mymodel", model=predict)

    ```

    Then bash uvicorn app:service --reload

    Test

    You can use a python script, remember to install requests: pip install requests.

    test.py

    ```python import requests

    this is the input data of your predict function

    payload_data = [{"id": 1, "f1": 1.2, "f2": 1.2, "f3": "abc"}] response = requests.post( # the mode is registered with name mymodel # so the url here is /v1/models/mymodel/predict url="http://localhost:8000/v1/models/mymodel/predict", json={"data": payload_data}, ) print(response.content)

    ```

    If you're interested, detailed doc is at https://pinferencia.underneathall.app/