Ahmed Essam commited on
Update handler.py
Browse files123456789101112131415161718192021222324252627282930313233343536from typing import Dict, Anyimport torchimport base64from io import BytesIOfrom model import Modelfrom PIL import Image# set devicedevice = torch.device('cuda' if torch.cuda.is_available() else 'cpu')if device.type != 'cuda':raise ValueError("need to run on GPU")class EndpointHandler():def __init__(self, path=""):# load the optimized modelself.model = Model()def __call__(self, data: Any) -> Any:"""Args:data (:obj:):includes the input data and the parameters for the inference.Return:A :obj:`dict`:. base64 encoded image"""inputs = data.pop("image", data)image = Image.open(BytesIO(base64.b64decode(inputs)))# run inference pipeline_, res = self.model.process_lineart(image = image)# encoding image as base 64 is done by the default toolkitreturn res12345678910111213141516171819202122232425262728293031323334353637from typing import Dict, Anyimport torchimport base64from io import BytesIOfrom model import Modelfrom PIL import Image# set devicedevice = torch.device('cuda' if torch.cuda.is_available() else 'cpu')if device.type != 'cuda':raise ValueError("need to run on GPU")class EndpointHandler():def __init__(self, path=""):# load the optimized modelself.model = Model()def __call__(self, data: Any) -> Any:"""Args:data (:obj:):includes the input data and the parameters for the inference.Return:A :obj:`dict`:. base64 encoded image"""inputs = data.pop("inputs", data)image = Image.open(BytesIO(base64.b64decode(inputs['image'])))# run inference pipeline_, res = self.model.process_lineart(image)# encoding image as base 64 is done by the default toolkitreturn res
handler.py+37-36