File size: 1,154 Bytes
eea0bcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import tempfile
import os

import gradio as gr
import paddlehub as hub
from PIL import Image

pp_ocrv3 = hub.Module(name="ch_pp-ocrv3")

def inference(img):
    """
    [{'save_path': '', 'data': [{'text': '飞桨“大航海”计划', 'confidence': 0.9351316094398499, 'text_box_position': [[246, 16], [384, 14], [384, 33], [246, 35]]}, {'text': '产业智船化升圾', 'confidence': 0.8330735564231873, 'text_box_position': [[433, 109], [487, 109], [487, 119], [433, 119]]}]}]
    """
    results = pp_ocrv3.recognize_text(paths=[img],use_gpu=False,visualization=False)
    print(results)
    res = []
    data = results[0]['data']
    for item in data:
        if item['confidence'] > 0.75 and len(item['text']) > 0:
            res.append(item['text'])
    return res
  
title="ch_PP-OCRv3"
description="ch_PP-OCRv3 is a practical ultra-lightweight OCR system developed by PaddleOCR."

examples=[['test.png']]

gr.Interface(inference,gr.inputs.Image(type="filepath"),
             outputs=[gr.Textbox(label="Output Message")],
             title=title,
             description=description,
             examples=examples).launch(enable_queue=True)