CoolFace
Modelpublic

metafresh89/qr-code

sourceHugging Faceopenrail++updated 3y agoView on Hugging Face
4likes134downloads
handler.py26 linesDownload Raw Back to root
1from typing import Dict, List, Any2from PIL import Image3from io import BytesIO4from transformers import pipeline5import base646 7class EndpointHandler():8    def __init__(self, path=""):9        self.pipeline=pipeline("controlnet_qrcode-control_v11p_sd21",model=path)10    11    def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:12        """13       data args:14            images (:obj:`string`)15            candiates (:obj:`list`)16      Return:17            A :obj:`list`:. The list contains items that are dicts should be liked {"label": "XXX", "score": 0.82}18        """19        inputs = data.pop("inputs", data)20        prompts = data.pop("prompt", data)21 22        image = Image.open(BytesIO(base64.b64decode(inputs['image'])))23 24        # run prediction one image wit provided candiates25        prediction = self.pipeline(images=[image], prompt=[prompts])26        return prediction[0]