Ubuntu
commited on
Commit
·
b01db8a
1
Parent(s):
9be2d1c
change API
Browse files- app.py +21 -43
- images/demo2.png +0 -0
- images/demo3.png +0 -0
app.py
CHANGED
|
@@ -1,34 +1,17 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import requests
|
| 3 |
-
|
| 4 |
|
| 5 |
-
def
|
| 6 |
-
url = "
|
| 7 |
files = {'image': open(frame, 'rb')}
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
html = ("<table>"
|
| 15 |
-
"<tr>"
|
| 16 |
-
"<th style=""width:20%"">Field</th>"
|
| 17 |
-
"<th style=""width:40%"">Value</th>"
|
| 18 |
-
"<th style=""width:40%"">MRZ</th>"
|
| 19 |
-
"</tr>"
|
| 20 |
-
"{table_value}"
|
| 21 |
-
"</table>".format(table_value=table_value))
|
| 22 |
-
|
| 23 |
-
images = ("<table>"
|
| 24 |
-
"<tr>"
|
| 25 |
-
"<th>Field</th>"
|
| 26 |
-
"<th>Image</th>"
|
| 27 |
-
"</tr>"
|
| 28 |
-
"{table_value}"
|
| 29 |
-
"</table>".format(table_value=table_value))
|
| 30 |
-
|
| 31 |
-
return [html, images]
|
| 32 |
|
| 33 |
# APP Interface
|
| 34 |
with gr.Blocks() as MiniAIdemo:
|
|
@@ -37,7 +20,7 @@ with gr.Blocks() as MiniAIdemo:
|
|
| 37 |
<a href="https://miniai.live" style="display: flex; align-items: center;">
|
| 38 |
<img src="https://miniai.live/wp-content/uploads/2024/02/logo_name-1-768x426-1.png" style="width: 18%; margin-right: 15px;"/>
|
| 39 |
<div>
|
| 40 |
-
<p style="font-size: 50px; font-weight: bold; margin-right: 20px;">ID Document Liveness
|
| 41 |
</div>
|
| 42 |
</a>
|
| 43 |
|
|
@@ -52,25 +35,20 @@ with gr.Blocks() as MiniAIdemo:
|
|
| 52 |
"""
|
| 53 |
)
|
| 54 |
with gr.Tabs():
|
| 55 |
-
with gr.
|
| 56 |
with gr.Row():
|
| 57 |
-
with gr.Column(
|
| 58 |
-
|
| 59 |
gr.Examples(
|
| 60 |
[
|
| 61 |
-
"images/
|
| 62 |
-
"images/id/demo2.png",
|
| 63 |
-
"images/id/demo3.png",
|
| 64 |
],
|
| 65 |
-
inputs=
|
| 66 |
)
|
| 67 |
-
btn_f_idlive = gr.Button("
|
| 68 |
-
with gr.Column(
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
im_idlive_out = gr.HTML()
|
| 72 |
-
|
| 73 |
-
btn_f_idlive.click(check_idlive, inputs=im_idlive_in, outputs=[table_idlive_out, im_idlive_out])
|
| 74 |
|
| 75 |
if __name__ == "__main__":
|
| 76 |
-
MiniAIdemo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
import requests
|
| 4 |
+
import json
|
| 5 |
|
| 6 |
+
def check_id_liveness(frame):
|
| 7 |
+
url = "http://191.96.31.183:8093/api/check_id_liveness"
|
| 8 |
files = {'image': open(frame, 'rb')}
|
| 9 |
+
try:
|
| 10 |
+
r = requests.post(url=url, files=files)
|
| 11 |
+
r.raise_for_status()
|
| 12 |
+
return json.dumps(r.json(), indent=2)
|
| 13 |
+
except requests.exceptions.RequestException as e:
|
| 14 |
+
return str(e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
# APP Interface
|
| 17 |
with gr.Blocks() as MiniAIdemo:
|
|
|
|
| 20 |
<a href="https://miniai.live" style="display: flex; align-items: center;">
|
| 21 |
<img src="https://miniai.live/wp-content/uploads/2024/02/logo_name-1-768x426-1.png" style="width: 18%; margin-right: 15px;"/>
|
| 22 |
<div>
|
| 23 |
+
<p style="font-size: 50px; font-weight: bold; margin-right: 20px;">ID Document Liveness Detection Web Online Demo</p>
|
| 24 |
</div>
|
| 25 |
</a>
|
| 26 |
|
|
|
|
| 35 |
"""
|
| 36 |
)
|
| 37 |
with gr.Tabs():
|
| 38 |
+
with gr.TabItem("ID Document Liveness Detection"):
|
| 39 |
with gr.Row():
|
| 40 |
+
with gr.Column():
|
| 41 |
+
im_idlive_input = gr.Image(type='filepath', height=300)
|
| 42 |
gr.Examples(
|
| 43 |
[
|
| 44 |
+
os.path.join(os.path.dirname(__file__), "images/demo1.jpg"),
|
|
|
|
|
|
|
| 45 |
],
|
| 46 |
+
inputs=im_idlive_input
|
| 47 |
)
|
| 48 |
+
btn_f_idlive = gr.Button("Analysis Document", variant='primary')
|
| 49 |
+
with gr.Column():
|
| 50 |
+
txt_idlive_output = gr.Textbox(label="API Response (JSON)")
|
| 51 |
+
btn_f_idlive.click(check_id_liveness, inputs=im_idlive_input, outputs=txt_idlive_output)
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
if __name__ == "__main__":
|
| 54 |
+
MiniAIdemo.launch(server_port=8083, server_name="0.0.0.0")
|
images/demo2.png
DELETED
|
Binary file (775 kB)
|
|
|
images/demo3.png
DELETED
|
Binary file (289 kB)
|
|
|