cadyderwin commited on
Commit
e388f06
·
verified ·
1 Parent(s): 9f4b8c1

Upload 17 files

Browse files
.gitattributes CHANGED
@@ -34,3 +34,9 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
  examples/2.jpg filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
  examples/2.jpg filter=lfs diff=lfs merge=lfs -text
37
+ lib/libDocSdk.so filter=lfs diff=lfs merge=lfs -text
38
+ lib/libopenvino_intel_cpu_plugin.so filter=lfs diff=lfs merge=lfs -text
39
+ lib/libopenvino_onnx_frontend.so.2300 filter=lfs diff=lfs merge=lfs -text
40
+ lib/libopenvino.so.2300 filter=lfs diff=lfs merge=lfs -text
41
+ lib/libopenvino.so.2330 filter=lfs diff=lfs merge=lfs -text
42
+ lib/libopyidlive.so filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.8-slim
2
+ WORKDIR /home/opyidlive
3
+ COPY ./opyidlive.py .
4
+ COPY ./app.py .
5
+ COPY ./demo.py .
6
+ COPY ./license.txt .
7
+ COPY ./requirements.txt .
8
+ COPY ./run.sh .
9
+ COPY ./examples ./examples
10
+ COPY ./model ./model
11
+ COPY ./lib /usr/lib
12
+ COPY ./lib/libopyidlive.so ./lib/libopyidlive.so
13
+ RUN pip3 install -r requirements.txt
14
+ RUN chmod a+x run.sh
15
+ CMD ["./run.sh"]
16
+ EXPOSE 9000 7860
app.py ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ sys.path.append('.')
3
+
4
+ import os
5
+ import numpy as np
6
+ import base64
7
+ import json
8
+ import io
9
+
10
+ from PIL import Image, ExifTags
11
+ from flask import Flask, request, jsonify
12
+ from opymrz import getHWID
13
+ from opymrz import setLicenseKey
14
+ from opymrz import initSDK
15
+ from opymrz import processImage
16
+
17
+ licenseKeyPath = "license.txt"
18
+ license = ""
19
+
20
+ try:
21
+ with open(licenseKeyPath, 'r') as file:
22
+ license = file.read().strip()
23
+ except IOError as exc:
24
+ print("failed to open license.txt: ", exc.errno)
25
+ print("License Key: ", license)
26
+
27
+ hwid = getHWID()
28
+ print("HWID: ", hwid.decode('utf-8'))
29
+
30
+ ret = setLicenseKey(license.encode('utf-8'))
31
+ print("Set License: ", ret)
32
+
33
+ ret = initSDK("model".encode('utf-8'))
34
+ print("Init: ", ret)
35
+
36
+ app = Flask(__name__)
37
+
38
+ def apply_exif_rotation(image):
39
+ try:
40
+ exif = image._getexif()
41
+ if exif is not None:
42
+ for orientation in ExifTags.TAGS.keys():
43
+ if ExifTags.TAGS[orientation] == 'Orientation':
44
+ break
45
+
46
+ # Get the orientation value
47
+ orientation = exif.get(orientation, None)
48
+
49
+ # Apply the appropriate rotation based on the orientation
50
+ if orientation == 3:
51
+ image = image.rotate(180, expand=True)
52
+ elif orientation == 6:
53
+ image = image.rotate(270, expand=True)
54
+ elif orientation == 8:
55
+ image = image.rotate(90, expand=True)
56
+
57
+ except AttributeError:
58
+ print("No EXIF data found")
59
+
60
+ return image
61
+
62
+
63
+ @app.route('/process_image', methods=['POST'])
64
+ def process_image():
65
+ file = request.files['image']
66
+
67
+ try:
68
+ image = apply_exif_rotation(Image.open(file)).convert('RGB')
69
+ except:
70
+ result = "Failed to open file"
71
+ response = jsonify({"resultCode": "Error", "result": result})
72
+
73
+ response.status_code = 200
74
+ response.headers["Content-Type"] = "application/json; charset=utf-8"
75
+ return response
76
+
77
+ image_np = np.asarray(image)
78
+ result = processImage(image_np, image_np.shape[1], image_np.shape[0])
79
+
80
+ if result is None:
81
+ result = "Failed to process image"
82
+ response = jsonify({"resultCode": "Error", "result": result})
83
+
84
+ response.status_code = 200
85
+ response.headers["Content-Type"] = "application/json; charset=utf-8"
86
+ return response
87
+ else:
88
+ result_dict = json.loads(result.decode('utf-8'))
89
+ response = jsonify({"resultCode": "Ok", "result": result_dict})
90
+
91
+ response.status_code = 200
92
+ response.headers["Content-Type"] = "application/json; charset=utf-8"
93
+ return response
94
+
95
+ @app.route('/process_image_base64', methods=['POST'])
96
+ def process_image_base64():
97
+ try:
98
+ content = request.get_json()
99
+ base64_image = content['base64']
100
+
101
+ image_data = base64.b64decode(base64_image)
102
+ image = apply_exif_rotation(Image.open(io.BytesIO(image_data))).convert("RGB")
103
+ except:
104
+ result = "Failed to parse base64"
105
+ response = jsonify({"resultCode": "Error", "result": result})
106
+
107
+ response.status_code = 200
108
+ response.headers["Content-Type"] = "application/json; charset=utf-8"
109
+ return response
110
+
111
+ image_np = np.asarray(image)
112
+ result = processImage(image_np, image_np.shape[1], image_np.shape[0])
113
+
114
+ if result is None:
115
+ result = "Failed to process image"
116
+ response = jsonify({"resultCode": "Error", "result": result})
117
+
118
+ response.status_code = 200
119
+ response.headers["Content-Type"] = "application/json; charset=utf-8"
120
+ return response
121
+ else:
122
+ result_dict = json.loads(result.decode('utf-8'))
123
+ response = jsonify({"resultCode": "Ok", "result": result_dict})
124
+
125
+ response.status_code = 200
126
+ response.headers["Content-Type"] = "application/json; charset=utf-8"
127
+ return response
128
+
129
+ if __name__ == '__main__':
130
+ port = int(os.environ.get("PORT", 9000))
131
+ app.run(host='0.0.0.0', port=port)
demo.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import requests
4
+ import json
5
+ import io
6
+ from gradio.components import Image
7
+ from PIL import Image as PILImage, ImageDraw, ImageFont # This import may be needed if you're processing images
8
+
9
+ from PIL import Image
10
+
11
+ def process_image(image):
12
+ # Convert PIL image to bytes to send in POST request
13
+ img_bytes = io.BytesIO()
14
+ image.save(img_bytes, format="JPEG")
15
+ img_bytes.seek(0)
16
+
17
+
18
+ url = "http://127.0.0.1:9000/process_image"
19
+ files = {'image': img_bytes}
20
+ result = requests.post(url=url, files=files)
21
+ if result.ok:
22
+ json_result = result.json()
23
+ if json_result.get("resultCode") == "Error":
24
+ return [{"resultCode": "Error", "result": "Failed to process image"}]
25
+
26
+ return [json_result]
27
+ else:
28
+ return [{"resultCode": "Error", "result": result.text}]
29
+
30
+ with gr.Blocks() as demo:
31
+ gr.Markdown(
32
+ """
33
+ <div style="display: flex;align-items: center;">
34
+ <img alt="Opulentyn Logo" src="https://github.com/user-attachments/assets/5fc78032-bff2-4f7e-a174-7d64b22f506d" width="350"/>
35
+ <div>
36
+ <h1>Identity Document Liveness Detection</h1>
37
+ <p>We offer <b>on-premises</b> OCR and liveness check solutions available with a <b>perpetual license</b>.</p>
38
+ </div>
39
+ </div>
40
+
41
+ ## 🤝 Talk to us
42
+
43
+ <div style="display: flex; align-items: center;">
44
+ <a href="https://opulentyn.com" target="_blank">
45
+ <img src="https://img.shields.io/badge/Website-https%3A%2F%2Fopulentyn.com-blue?style=flat&logo=google-chrome&logoColor=white" alt="Website">
46
+ </a>
47
+ &nbsp;&nbsp;&nbsp;&nbsp;
48
+ <a href="mailto:support@opulentyn.com">
49
+ <img src="https://img.shields.io/badge/Email-support%40opulentyn.com-blue?style=flat&logo=gmail&logoColor=white" alt="Email">
50
+ </a>
51
+ &nbsp;&nbsp;&nbsp;&nbsp;
52
+ <a href="https://wa.me/13435013587" target="_blank">
53
+ <img src="https://img.shields.io/badge/WhatsApp-%2B13435013587-blue?logo=whatsapp&logoColor=green" alt="WhatsApp">
54
+ </a>
55
+ &nbsp;&nbsp;&nbsp;&nbsp;
56
+ <a href="https://join.slack.com/t/opulentyn/shared_invite/zt-2s230jtbq-dWBs8XUZcrYim~nUqiimSA" target="_blank">
57
+ <img src="https://img.shields.io/badge/Slack-support--sdk-blueviolet?style=flat&logo=slack&logoColor=white" alt="Slack">
58
+ </a>
59
+ </div>
60
+ """
61
+ )
62
+
63
+ with gr.Row():
64
+ with gr.Column():
65
+ image_input = gr.Image(type='pil')
66
+ gr.Examples(['examples/1.jpg', 'examples/2.jpg', 'examples/3.jpg'],
67
+ inputs=image_input)
68
+ process_button = gr.Button("Process")
69
+ with gr.Column():
70
+ json_output = gr.JSON()
71
+
72
+ process_button.click(process_image, inputs=[image_input], outputs=[json_output])
73
+
74
+ gr.HTML('<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2Fopulentyn%2FMrzOCR"><img src="https://api.visitorbadge.io/api/combined?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2Fopulentyn%2FMrzOCR&countColor=%23263759" /></a>')
75
+
76
+ demo.launch(server_name="0.0.0.0", server_port=7860)
lib/libDocSdk.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9e4fb0d2e876a1ef5d30ba988ac09d295ce9a38572479ae6dce6cf0c3f2ecb01
3
+ size 22300226
lib/libopenvino.so.2300 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4f5edb8e7f6c8f89ec76fdc4da0de79921fce630d4c20891d0c6378e3ebd1cbd
3
+ size 21726552
lib/libopenvino.so.2330 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3be612fe4606381cfddf1198b3ab1a851c0fdbd8490ddb101577f82b1678ce78
3
+ size 22302048
lib/libopenvino_intel_cpu_plugin.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1de80e57d72249ab45de0f0ab807f729a86360248ca4f4d23c203882e7736f21
3
+ size 45820616
lib/libopenvino_ir_frontend.so.2330 ADDED
Binary file (594 kB). View file
 
lib/libopenvino_onnx_frontend.so.2300 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:924bb07b0964f3657a51772fc788c2a44d028439d6898d5d7e9ab889f34660de
3
+ size 5568776
lib/libopyidlive.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b62a4e0f480c098dd06237b3cdc0a8ed68e120d30aed053e049126acbcb69622
3
+ size 3522048
lib/libtbb.so.12 ADDED
Binary file (366 kB). View file
 
lib/plugins.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ <ie>
2
+ <plugins>
3
+ <plugin name="CPU" location="libopenvino_intel_cpu_plugin.so">
4
+ </plugin>
5
+ </plugins>
6
+ </ie>
license.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ OgZKxti3gyotiixapwPFgjgWEBvryxNmtnvuXsZdy3VLYvPOTQ0cCABAlp/tLV7FeBGGLMcMSb8UUAbEbtgOhVcFVEtfkFS/aQHrYHPyQ/XueNbiev6HaRxt7O136mMpNJRxjYqwoCvcfZcAE1GMByh+DSFkMzAhUbKYCjlj87c=
opyidlive.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ from ctypes import *
4
+ from numpy.ctypeslib import ndpointer
5
+
6
+ libPath = os.path.abspath(os.path.dirname(__file__)) + '/lib/libopymrzenv.so'
7
+ libopymrzenv = cdll.LoadLibrary(libPath)
8
+
9
+ libPath = os.path.abspath(os.path.dirname(__file__)) + '/lib/libopymrz.so'
10
+ libopymrz = cdll.LoadLibrary(libPath)
11
+
12
+ getHWID = libopymrz.getHWID
13
+ getHWID.argtypes = []
14
+ getHWID.restype = c_char_p
15
+
16
+ setLicenseKey = libopymrz.setLicenseKey
17
+ setLicenseKey.argtypes = [c_char_p]
18
+ setLicenseKey.restype = c_int32
19
+
20
+ initSDK = libopymrz.initSDK
21
+ initSDK.argtypes = [c_char_p]
22
+ initSDK.restype = c_int32
23
+
24
+ processImage = libopymrz.processImage
25
+ processImage.argtypes = [ndpointer(c_ubyte, flags='C_CONTIGUOUS'), c_int32, c_int32]
26
+ processImage.restype = c_char_p
27
+
readme.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ sudo docker build --pull --rm -f Dockerfile -t opyidlive:latest .
2
+ sudo docker run -v ./license.txt:/home/opyidlive/license.txt -p 7860:7860 -p 9000:9000 opyidlive
3
+
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ flask
2
+ flask-cors
3
+ gradio
4
+ datadog_api_client
run.sh ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ cd /home/opyidlive
4
+ exec python3 demo.py &
5
+ exec python3 app.py