import gradio as gr import requests request_method_map = { '同步': 'sync', '异步': 'async', } tasks_map = { '关键词提取': 'keywords', 'ocr': 'ocr', '表格': 'ocr_table', } subtask_map = { '身份证': 'id_card', '信息表': 'inform_table', '营业执照': 'bus_lic', '银行卡信息': 'bank_info', '用户信息采集表': 'user_info_collect', } def ocr_task(request_method, tasks, subtask, file, url): """ :param request_method: :param tasks: :param subtask: :param file: :param url: :return: """ res = requests.post(url, data={ 'file': file, 'request_method': request_method_map.get(request_method), 'tasks': tasks_map.get(tasks), 'subtask': subtask_map.get(subtask), 'angle': 0, }) return str(res.json()) def ocr_tab(): with gr.Tab("ocr 识别"): gr.Markdown('ocr 工具') with gr.Accordion("说明", open=False): gr.Markdown(""" # Hello World! 嘤嘤嘤 嘻嘻嘻 """) with gr.Column(): url_input = gr.Textbox(label='接口链接') with gr.Row(): request_method = gr.Dropdown(choices=list(request_method_map.keys()), label='运行方式') tasks = gr.Dropdown(choices=list(tasks_map.keys()), label='模式') subtask = gr.Dropdown(choices=list(subtask_map.keys()), label='文件类型') file = gr.File(type='file') text_output = gr.Textbox(label="结果", lines=10) text_button = gr.Button('识别') text_button.click(ocr_task, inputs=[request_method, tasks, subtask, file, url_input], outputs=text_output)