File size: 876 Bytes
41f99fa
 
 
 
884f0af
 
41f99fa
 
 
 
 
 
 
 
 
 
 
ead4cda
884f0af
 
41f99fa
884f0af
 
 
 
 
41f99fa
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from typing import Dict, List, Any
from transformers import pipeline
import transformers
from PIL import Image
import base64
from io import BytesIO

print('TRANSFORMERS VERSION')
print(transformers.__version__)

class EndpointHandler():
    def __init__(self, path=""):
        # load pipe
        self.pipe = pipeline(task="depth-estimation", model=path)


    def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
        base64_image = data.pop("inputs",data)
        if base64_image is None:
            raise ValueError("No image provided")

        if base64_image.startswith('data:image/jpeg;base64,'):
            base64_image = base64_image.replace('data:image/jpeg;base64,', '')

        image_bytes = base64.b64decode(base64_image)
        image = Image.open(BytesIO(image_bytes))

        depth = self.pipe(image)["depth"]
        
        return depth