Hi, I would like to use multipart input in my serv...
# ask-for-help
y
Hi, I would like to use multipart input in my service class but the multipart examples are show in this format where svc.api decorater is used:
Copy code
svc = bentoml.Service("iris-classifier", runners=[runner])

input_spec = Multipart(arr=NumpyNdarray(), annotations=JSON())
output_spec = Multipart(output=NumpyNdarray(), result=JSON())

@svc.api(input=input_spec, output=output_spec)
async def predict(
    arr: NDArray[Any], annotations: dict[str, Any]
) -> dict[str, NDArray[Any] | dict[str, Any]]:
    res = await runner.run(arr)
    return {"output": res, "result": annotations}
but I have a class like following which I do lots of stuff init, but I cant give multipart input to that • input argument not exists instead there is input_spec which doesn't work either
Copy code
import bentoml
bentoml.service(
)
class ClipService:
    """BentoML service for encoding text and images using CLIP models."""

    def __init__(self):
        super().__init__()
        # I am doing something in here

    @bentoml.api(input=Multipart(images=File(), metadata=JSON()), batchable=True)
    async def encode_image(self, images: List[UploadFile], metadata: dict[str, Any]):
        # this doesn't work
Any idea?
t
I can't give you an elaborate answer, but I have a multipart api endpoint accepting an image and a json configuration object:
Copy code
class HeatmapConfiguration(BaseModel):
    with_overlay: bool = False
    class_index: int = 0

@bentoml.api
def heatmap(self, input_image: PILImage.Image, configuration: HeatmapConfiguration) -> PILImage.Image:
    ...
c
you probably found the example code for BentoML 1.1, for latest BentoML, you can use multipart input like this: https://docs.bentoml.com/en/latest/guides/iotypes.html#compound