File size: 3,766 Bytes
31cbc2e 9b308b4 31cbc2e 0174efb 31cbc2e 029ea56 31cbc2e 0174efb 31cbc2e 30e7b08 1f3eb37 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
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/", token)
client_lic = Client("https://vtechai-ocr-license.hf.space/", token)
client_vis = Client("https://vtechai-ocr-cardvisit.hf.space/", 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
def ocr_vis(img, lang):
js = client_vis.predict(img, lang, fn_index=1)
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, im2, 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 cardvisit_lb:
with gr.Row():
with gr.Column():
im1 = gr.Image(height=500, type='filepath', container=True)
lang = gr.Radio(["vi", "en", "ja"], label="Language", value="vi")
with gr.Column():
js = gr.JSON(label="json")
with gr.Row():
btn = gr.Button(value="Run")
btn_clean = gr.ClearButton([im1, lang, js])
btn.click(fn=ocr_vis, inputs=[im1, lang], 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, cardvisit_lb], ["CMT/CCCD", "PassPort", "Bằng lái xe", "Đăng ký xe", "Danh thiếp"])
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 của bạn</span>.')
if __name__ == "__main__":
demo.launch() |