arguments to handleer
Browse files- 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 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
|
|
|
| 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}
|