feat(platform): harden telemetry pipeline and unify Semi UI workspaces
This commit is contained in:
10
deploy/feichi-ocr/Dockerfile
Normal file
10
deploy/feichi-ocr/Dockerfile
Normal file
@@ -0,0 +1,10 @@
|
||||
FROM python:3.11-slim
|
||||
|
||||
RUN pip install --no-cache-dir \
|
||||
--index-url https://mirrors.aliyun.com/pypi/simple \
|
||||
ddddocr==1.6.1
|
||||
|
||||
WORKDIR /app
|
||||
COPY ocr.py /app/ocr.py
|
||||
USER nobody
|
||||
ENTRYPOINT ["python", "/app/ocr.py"]
|
||||
22
deploy/feichi-ocr/ocr.py
Normal file
22
deploy/feichi-ocr/ocr.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import re
|
||||
import sys
|
||||
|
||||
import ddddocr
|
||||
|
||||
|
||||
def main() -> int:
|
||||
image = sys.stdin.buffer.read()
|
||||
if not image:
|
||||
print("captcha image is empty", file=sys.stderr)
|
||||
return 2
|
||||
result = ddddocr.DdddOcr(show_ad=False).classification(image)
|
||||
code = re.sub(r"[^0-9A-Za-z]", "", result).upper()
|
||||
if not re.fullmatch(r"[0-9A-Z]{4}", code):
|
||||
print(f"invalid OCR result: {code!r}", file=sys.stderr)
|
||||
return 3
|
||||
print(code)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user