jonahkaye commited on
Commit
bdfbfc5
1 Parent(s): e7604fc

arguments to handleer

Browse files
Files changed (1) hide show
  1. handler.py +19 -10
handler.py CHANGED
@@ -12,14 +12,23 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
12
 
13
 
14
  class EndpointHandler:
15
- def __call__(self, data: Dict[str, bytes]) -> Dict[str, List[Any]]:
16
- """
17
- Args:
18
- data (:obj:):
19
- includes the deserialized image file as PIL.Image
20
- """
21
- # process input
22
- image = data.pop("inputs", data)
 
 
 
 
 
 
 
 
 
23
 
24
- result = pytesseract.image_to_string(image)
25
- return {"predictions": result}
 
12
 
13
 
14
  class EndpointHandler:
15
+
16
+ def __init__(self, path=""):
17
+ self.pytesseract_installed = False
18
+ try:
19
+ import pytesseract
20
+ self.pytesseract_installed = True
21
+ except ImportError:
22
+ print("Pytesseract not installed, will not use OCR")
23
+
24
+ def __call__(self, data: Dict[str, bytes]) -> Dict[str, List[Any]]:
25
+ """
26
+ Args:
27
+ data (:obj:):
28
+ includes the deserialized image file as PIL.Image
29
+ """
30
+ # process input
31
+ image = data.pop("inputs", data)
32
 
33
+ result = pytesseract.image_to_string(image)
34
+ return {"predictions": result}