halimb commited on
Commit
884f0af
1 Parent(s): b568011

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +10 -6
handler.py CHANGED
@@ -2,7 +2,8 @@ from typing import Dict, List, Any
2
  from transformers import pipeline
3
  import transformers
4
  from PIL import Image
5
- import requests
 
6
 
7
  print('TRANSFORMERS VERSION')
8
  print(transformers.__version__)
@@ -14,12 +15,15 @@ class EndpointHandler():
14
 
15
 
16
  def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
17
- # get inputs
18
- # image = data.pop("image",data)
 
19
 
20
- # load image
21
- url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
22
- image = Image.open(requests.get(url, stream=True).raw)
 
 
23
 
24
  depth = self.pipe(image)["depth"]
25
 
 
2
  from transformers import pipeline
3
  import transformers
4
  from PIL import Image
5
+ import base64
6
+ from io import BytesIO
7
 
8
  print('TRANSFORMERS VERSION')
9
  print(transformers.__version__)
 
15
 
16
 
17
  def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
18
+ base64_image = data.get("image")
19
+ if base64_image is None:
20
+ raise ValueError("No image provided")
21
 
22
+ if base64_image.startswith('data:image/jpeg;base64,'):
23
+ base64_image = base64_image.replace('data:image/jpeg;base64,', '')
24
+
25
+ image_bytes = base64.b64decode(base64_image)
26
+ image = Image.open(BytesIO(image_bytes))
27
 
28
  depth = self.pipe(image)["depth"]
29