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('

V-Reader

') 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('*Chúng tôi cam kết không lưu trữ và sử dụng dữ liệu của bạn.') if __name__ == "__main__": demo.launch()