sitloboi2012
commited on
Commit
·
96ac1a0
1
Parent(s):
bb8f1a5
update handler
Browse files- Dockerfile +29 -0
- handler.py +2 -2
Dockerfile
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9-slim-bullseye AS base
|
2 |
+
WORKDIR /app
|
3 |
+
|
4 |
+
FROM base AS build
|
5 |
+
COPY ["requirements.txt", "./"]
|
6 |
+
RUN \
|
7 |
+
apt-get update && \
|
8 |
+
apt-get install -y --no-install-recommends \
|
9 |
+
git \
|
10 |
+
g++ && \
|
11 |
+
rm -rf /var/lib/apt/lists/* && \
|
12 |
+
# Install dependencies.
|
13 |
+
python -m venv ./venv && \
|
14 |
+
./venv/bin/pip install --upgrade \
|
15 |
+
pip \
|
16 |
+
setuptools \
|
17 |
+
wheel && \
|
18 |
+
./venv/bin/pip install --no-cache-dir -r ./requirements.txt && \
|
19 |
+
./venv/bin/pip install --no-cache-dir 'git+https://github.com/facebookresearch/detectron2.git@d1e04565d3bec8719335b88be9e9b961bf3ec464'
|
20 |
+
|
21 |
+
FROM base AS final
|
22 |
+
RUN \
|
23 |
+
apt-get update && \
|
24 |
+
apt-get install -y --no-install-recommends \
|
25 |
+
tesseract-ocr && \
|
26 |
+
rm -rf /var/lib/apt/lists/*
|
27 |
+
COPY --from=build ["/app/venv", "./venv"]
|
28 |
+
# Copy the source code in last to optimize rebuilding the image.
|
29 |
+
COPY [".", "./"]
|
handler.py
CHANGED
@@ -21,8 +21,8 @@ class EndpointHandler:
|
|
21 |
self.PROCESSOR = LayoutLMv3Processor(self.FEATURE_EXTRACTOR, self.TOKENIZER)
|
22 |
self.MODEL = LayoutLMv3ForSequenceClassification.from_pretrained("OtraBoi/document_classifier_testing").to(device)
|
23 |
|
24 |
-
def __call__(self, data:
|
25 |
-
image = Image.open(io.BytesIO(data)).convert("RGB")
|
26 |
encoding = self.PROCESSOR(image, return_tensors="pt", padding="max_length", truncation=True)
|
27 |
|
28 |
for k,v in encoding.items():
|
|
|
21 |
self.PROCESSOR = LayoutLMv3Processor(self.FEATURE_EXTRACTOR, self.TOKENIZER)
|
22 |
self.MODEL = LayoutLMv3ForSequenceClassification.from_pretrained("OtraBoi/document_classifier_testing").to(device)
|
23 |
|
24 |
+
def __call__(self, data: Dict):
|
25 |
+
image = Image.open(io.BytesIO(data["inputs"])).convert("RGB")
|
26 |
encoding = self.PROCESSOR(image, return_tensors="pt", padding="max_length", truncation=True)
|
27 |
|
28 |
for k,v in encoding.items():
|