from mmocr.ocr import MMOCR import gradio as gr import cv2 model_dir = 'work_dirs/dbnet_resnet18_fpnc_1200e_icdar2015' ocr = MMOCR(det='DB_r18', det_config=f'{model_dir}/dbnet_resnet18_fpnc_1200e_icdar2015.py', det_ckpt=f'{model_dir}/epoch_40.pth' ) def predict(inp): return str(ocr.readtext(inp)) def run(): demo = gr.Interface( fn=predict, inputs=gr.inputs.Image(), outputs=gr.outputs.Textbox(), ) demo.launch(server_name="0.0.0.0", server_port=7860) if __name__ == "__main__": run()