Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -78,6 +78,7 @@ def json_to_html_table(data, image_keys):
|
|
| 78 |
return html
|
| 79 |
|
| 80 |
def check_liveness(frame):
|
|
|
|
| 81 |
if frame is None:
|
| 82 |
liveness_result = f"""<div class="markdown-fail-container"><p style="text-align: center; font-size: 20px; color: red;">Liveness Check Failed</p></div>"""
|
| 83 |
return [liveness_result, {"status": "error", "result": "select image file!"}]
|
|
@@ -86,23 +87,30 @@ def check_liveness(frame):
|
|
| 86 |
Image.open(frame).save(img_bytes, format="JPEG")
|
| 87 |
img_bytes.seek(0)
|
| 88 |
|
| 89 |
-
url = "https://
|
| 90 |
|
| 91 |
try:
|
| 92 |
-
files =
|
| 93 |
-
|
|
|
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
result = requests.post(url=url, files=files, headers=headers)
|
| 96 |
except:
|
| 97 |
liveness_result = f"""<div class="markdown-fail-container"><p style="text-align: center; font-size: 20px; color: red;">Liveness Check Failed</p></div>"""
|
| 98 |
return [liveness_result, {"status": "error", "result": "failed to open file!"}]
|
| 99 |
-
|
| 100 |
if result.ok:
|
| 101 |
json_result = result.json()
|
| 102 |
if json_result.get("resultCode") == "Error":
|
| 103 |
liveness_result = f"""<div class="markdown-fail-container"><p style="text-align: center; font-size: 20px; color: red;">Liveness Check Failed</p></div>"""
|
| 104 |
return [liveness_result, {"status": "error", "result": "server error!"}]
|
| 105 |
-
|
|
|
|
|
|
|
| 106 |
process_results = json_result.get("result")
|
| 107 |
status = process_results.get("status")
|
| 108 |
if status == "Ok":
|
|
@@ -128,12 +136,9 @@ def check_liveness(frame):
|
|
| 128 |
return [liveness_result, {"status": "error", "result": f"{result.text}"}]
|
| 129 |
|
| 130 |
def idcard_recognition(frame1):
|
| 131 |
-
# url = "https://recognito-iddocumentrecognition.p.rapidapi.com/api/read_idcard"
|
| 132 |
url = "https://api.cortex.cerebrium.ai/v4/p-4f1d877e/my-first-project/process-image/"
|
| 133 |
# url = "https://edreesi-ocr-api.hf.space/process-image/"
|
| 134 |
|
| 135 |
-
|
| 136 |
-
|
| 137 |
files = None
|
| 138 |
if frame1 is not None:
|
| 139 |
# Open the image using Pillow
|
|
@@ -289,7 +294,7 @@ def launch_demo():
|
|
| 289 |
|
| 290 |
id_recognition_button.click(idcard_recognition, inputs=id_image_input1, outputs=[id_result_output, json_result_output, image_result_output])
|
| 291 |
|
| 292 |
-
with gr.Tab("
|
| 293 |
with gr.Row():
|
| 294 |
with gr.Column(scale=1):
|
| 295 |
id_image_input = gr.Image(label="Image", type='filepath', elem_classes="example-image")
|
|
|
|
| 78 |
return html
|
| 79 |
|
| 80 |
def check_liveness(frame):
|
| 81 |
+
|
| 82 |
if frame is None:
|
| 83 |
liveness_result = f"""<div class="markdown-fail-container"><p style="text-align: center; font-size: 20px; color: red;">Liveness Check Failed</p></div>"""
|
| 84 |
return [liveness_result, {"status": "error", "result": "select image file!"}]
|
|
|
|
| 87 |
Image.open(frame).save(img_bytes, format="JPEG")
|
| 88 |
img_bytes.seek(0)
|
| 89 |
|
| 90 |
+
url = "https://api.cortex.cerebrium.ai/v4/p-4f1d877e/my-first-project/check-liveness/"
|
| 91 |
|
| 92 |
try:
|
| 93 |
+
files = [
|
| 94 |
+
('file', ('image.jpg', img_bytes, 'image/jpeg'))
|
| 95 |
+
]
|
| 96 |
|
| 97 |
+
headers = {
|
| 98 |
+
'Authorization': 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJwcm9qZWN0SWQiOiJwLTRmMWQ4NzdlIiwiaWF0IjoxNzM5MjM2NjA5LCJleHAiOjIwNTQ4MTI2MDl9.0LH0iOnqHZfKTH4GF5iTZ4qNj5vylCryo8rBnErljsq2qD2cpVTetCqhKtnbstTUEjuv6MAJw9jt58z-QNJfYLK9sJcnBhawTR3iM2Ap_bFyjlzg2LbgkwRPjUVJkkcuCRhBKyebXwvqQBvWyOtMq6UekauumbmYBRbA2-T4u343YD4tO2xIfsTsTXznALp1SechjRuys-3xo3ZQbUs05_p38fOFucKI-abc91Eq6sIOkLFjYEM68yuV0UBWl-OSpPu66e0SClroAVlKFDMPS9MY0Jr7X1pBYX4jew6vozj9D8Y-HS-KkdPFqJ7HrZOfQd0wGUgYJHyC58yReWXaRQ',
|
| 99 |
+
# 'Content-Type': 'application/json'
|
| 100 |
+
}
|
| 101 |
result = requests.post(url=url, files=files, headers=headers)
|
| 102 |
except:
|
| 103 |
liveness_result = f"""<div class="markdown-fail-container"><p style="text-align: center; font-size: 20px; color: red;">Liveness Check Failed</p></div>"""
|
| 104 |
return [liveness_result, {"status": "error", "result": "failed to open file!"}]
|
| 105 |
+
print("the result is", result)
|
| 106 |
if result.ok:
|
| 107 |
json_result = result.json()
|
| 108 |
if json_result.get("resultCode") == "Error":
|
| 109 |
liveness_result = f"""<div class="markdown-fail-container"><p style="text-align: center; font-size: 20px; color: red;">Liveness Check Failed</p></div>"""
|
| 110 |
return [liveness_result, {"status": "error", "result": "server error!"}]
|
| 111 |
+
# if 'data' in r.json():
|
| 112 |
+
# data = r.json()['data']
|
| 113 |
+
|
| 114 |
process_results = json_result.get("result")
|
| 115 |
status = process_results.get("status")
|
| 116 |
if status == "Ok":
|
|
|
|
| 136 |
return [liveness_result, {"status": "error", "result": f"{result.text}"}]
|
| 137 |
|
| 138 |
def idcard_recognition(frame1):
|
|
|
|
| 139 |
url = "https://api.cortex.cerebrium.ai/v4/p-4f1d877e/my-first-project/process-image/"
|
| 140 |
# url = "https://edreesi-ocr-api.hf.space/process-image/"
|
| 141 |
|
|
|
|
|
|
|
| 142 |
files = None
|
| 143 |
if frame1 is not None:
|
| 144 |
# Open the image using Pillow
|
|
|
|
| 294 |
|
| 295 |
id_recognition_button.click(idcard_recognition, inputs=id_image_input1, outputs=[id_result_output, json_result_output, image_result_output])
|
| 296 |
|
| 297 |
+
with gr.Tab("Id Card Liveness Detection"):
|
| 298 |
with gr.Row():
|
| 299 |
with gr.Column(scale=1):
|
| 300 |
id_image_input = gr.Image(label="Image", type='filepath', elem_classes="example-image")
|