Duy-NM
commited on
Commit
•
31cbc2e
1
Parent(s):
af7cadf
init
Browse files
app.py
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
import gradio as gr
|
4 |
+
from gradio_client import Client
|
5 |
+
|
6 |
+
token = os.environ['token']
|
7 |
+
client_cmt = Client("https://vtechai-ocr-cmt.hf.space/--replicas/crwgk/", token)
|
8 |
+
client_lic = Client("https://vtechai-ocr-license.hf.space/--replicas/cppkz/", token)
|
9 |
+
|
10 |
+
|
11 |
+
def ocr_cmt(img1, img2):
|
12 |
+
js = client_cmt.predict(img1, img2, fn_index=1)
|
13 |
+
with open(js) as f:
|
14 |
+
result = json.load(f)
|
15 |
+
|
16 |
+
return result
|
17 |
+
|
18 |
+
def ocr_pp(img):
|
19 |
+
js = client_cmt.predict(img, fn_index=3)
|
20 |
+
with open(js) as f:
|
21 |
+
result = json.load(f)
|
22 |
+
|
23 |
+
return result
|
24 |
+
|
25 |
+
def ocr_license(img):
|
26 |
+
js = client_lic.predict(img, fn_index=1)
|
27 |
+
with open(js) as f:
|
28 |
+
result = json.load(f)
|
29 |
+
|
30 |
+
return result
|
31 |
+
|
32 |
+
def ocr_regi(img):
|
33 |
+
js = client_lic.predict(img, fn_index=3)
|
34 |
+
with open(js) as f:
|
35 |
+
result = json.load(f)
|
36 |
+
|
37 |
+
return result
|
38 |
+
|
39 |
+
|
40 |
+
with gr.Blocks() as idcard_bl:
|
41 |
+
with gr.Row():
|
42 |
+
im1 = gr.Image(height=500, type='filepath', container=True, label='Mặt trước CMT/CCCD')
|
43 |
+
im2 = gr.Image(height=500, type='filepath', container=True, label='Mặt sau CMT/CCCD')
|
44 |
+
with gr.Row():
|
45 |
+
js = gr.JSON(label="json")
|
46 |
+
# area = gr.Radio(["Asia", "Europe/America"], label="Area?", value="Asia")
|
47 |
+
with gr.Row():
|
48 |
+
btn = gr.Button(value="Run")
|
49 |
+
btn_clean = gr.ClearButton([im1, js])
|
50 |
+
btn.click(fn=ocr_cmt, inputs=[im1, im2], outputs=[js])
|
51 |
+
|
52 |
+
with gr.Blocks() as pp_bl:
|
53 |
+
with gr.Row():
|
54 |
+
im1 = gr.Image(height=500, type='filepath', container=True)
|
55 |
+
js = gr.JSON(label="json")
|
56 |
+
# area = gr.Radio(["Asia", "Europe/America"], label="Area?", value="Asia")
|
57 |
+
with gr.Row():
|
58 |
+
btn = gr.Button(value="Run")
|
59 |
+
btn_clean = gr.ClearButton([im1, js])
|
60 |
+
|
61 |
+
btn.click(fn=ocr_pp, inputs=[im1], outputs=[js])
|
62 |
+
|
63 |
+
with gr.Blocks() as license_bl:
|
64 |
+
with gr.Row():
|
65 |
+
im1 = gr.Image(height=500, type='filepath', container=True)
|
66 |
+
js = gr.JSON(label="json")
|
67 |
+
# area = gr.Radio(["Asia", "Europe/America"], label="Area?", value="Asia")
|
68 |
+
with gr.Row():
|
69 |
+
btn = gr.Button(value="Run")
|
70 |
+
btn_clean = gr.ClearButton([im1, js])
|
71 |
+
|
72 |
+
btn.click(fn=ocr_license, inputs=[im1], outputs=[js])
|
73 |
+
|
74 |
+
with gr.Blocks() as register_bl:
|
75 |
+
with gr.Row():
|
76 |
+
im1 = gr.Image(height=500, type='filepath', container=True)
|
77 |
+
js = gr.JSON(label="json")
|
78 |
+
# area = gr.Radio(["Asia", "Europe/America"], label="Area?", value="Asia")
|
79 |
+
with gr.Row():
|
80 |
+
btn = gr.Button(value="Run")
|
81 |
+
btn_clean = gr.ClearButton([im1, js])
|
82 |
+
|
83 |
+
btn.click(fn=ocr_regi, inputs=[im1], outputs=[js])
|
84 |
+
|
85 |
+
with gr.Blocks() as demo:
|
86 |
+
gr.Markdown('<h1 style="text-align: center;">V-Reader</h1>')
|
87 |
+
gr.Markdown("*Chọn chức năng bạn muốn trải nghiệm")
|
88 |
+
gr.TabbedInterface([idcard_bl, pp_bl, license_bl, register_bl], ["CMT/CCCD", "PassPort", "Bằng lái xe", "Đăng ký xe"])
|
89 |
+
gr.Markdown('<span style="color:red">*Chúng tôi cam kết không lưu trữ và sử dụng dữ liệu khách hàng</span>.')
|
90 |
+
|
91 |
+
|
92 |
+
if __name__ == "__main__":
|
93 |
+
demo.launch()
|