File size: 3,070 Bytes
31cbc2e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import os
import json
import gradio as gr
from gradio_client import Client

token = os.environ['token']
client_cmt = Client("https://vtechai-ocr-cmt.hf.space/--replicas/crwgk/", token)
client_lic = Client("https://vtechai-ocr-license.hf.space/--replicas/cppkz/", token)


def ocr_cmt(img1, img2):
    js = client_cmt.predict(img1, img2, fn_index=1)
    with open(js) as f:
        result = json.load(f)
    
    return result 

def ocr_pp(img):
    js = client_cmt.predict(img, fn_index=3)
    with open(js) as f:
        result = json.load(f)
    
    return result 

def ocr_license(img):
    js = client_lic.predict(img, fn_index=1)
    with open(js) as f:
        result = json.load(f)
    
    return result

def ocr_regi(img):
    js = client_lic.predict(img, fn_index=3)
    with open(js) as f:
        result = json.load(f)
    
    return result


with gr.Blocks() as idcard_bl:
    with gr.Row():
        im1 = gr.Image(height=500,  type='filepath', container=True, label='Mặt trước CMT/CCCD')
        im2 = gr.Image(height=500,  type='filepath', container=True, label='Mặt sau CMT/CCCD')
    with gr.Row():
        js = gr.JSON(label="json")
        # area = gr.Radio(["Asia", "Europe/America"], label="Area?", value="Asia")
    with gr.Row():
        btn = gr.Button(value="Run")
        btn_clean = gr.ClearButton([im1, js])
    btn.click(fn=ocr_cmt, inputs=[im1, im2], outputs=[js])

with gr.Blocks() as pp_bl:
    with gr.Row():
        im1 = gr.Image(height=500, type='filepath', container=True)
        js = gr.JSON(label="json")
        # area = gr.Radio(["Asia", "Europe/America"], label="Area?", value="Asia")
    with gr.Row():
        btn = gr.Button(value="Run")
        btn_clean = gr.ClearButton([im1, js])
    
    btn.click(fn=ocr_pp, inputs=[im1], outputs=[js])

with gr.Blocks() as license_bl:
    with gr.Row():
        im1 = gr.Image(height=500, type='filepath', container=True)
        js = gr.JSON(label="json")
        # area = gr.Radio(["Asia", "Europe/America"], label="Area?", value="Asia")
    with gr.Row():
        btn = gr.Button(value="Run")
        btn_clean = gr.ClearButton([im1, js])
    
    btn.click(fn=ocr_license, inputs=[im1], outputs=[js])

with gr.Blocks() as register_bl:
    with gr.Row():
        im1 = gr.Image(height=500, type='filepath', container=True)
        js = gr.JSON(label="json")
        # area = gr.Radio(["Asia", "Europe/America"], label="Area?", value="Asia")
    with gr.Row():
        btn = gr.Button(value="Run")
        btn_clean = gr.ClearButton([im1, js])
    
    btn.click(fn=ocr_regi, inputs=[im1], outputs=[js])

with gr.Blocks() as demo:
    gr.Markdown('<h1 style="text-align: center;">V-Reader</h1>')
    gr.Markdown("*Chọn chức năng bạn muốn trải nghiệm")
    gr.TabbedInterface([idcard_bl, pp_bl, license_bl, register_bl], ["CMT/CCCD", "PassPort", "Bằng lái xe", "Đăng ký xe"])
    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>.')


if __name__ == "__main__":
    demo.launch()