| 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") |
| |
| 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") |
| |
| 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") |
| |
| 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") |
| |
| 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() |