File size: 640 Bytes
9a55fc0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from PIL import Image
from vietocr.tool.predictor import Predictor
from vietocr.tool.config import Cfg


config = Cfg.load_config_from_name('vgg_transformer')
config['weights'] = 'ocr.pth'
config['device'] = 'cuda:0'
config['cnn']['pretrained']=False
config['predictor']['beamsearch']=False

detector = Predictor(config)


def run(source):
    global detector
    img = Image.open(source) 
    img = img.convert('L') 
    result = detector.predict(img)
    return result
    

gr.Interface(
    run,
    inputs=gr.Image(label="Upload image", type="filepath"),
    outputs="label",
    title="Transformer Ocr",
).launch()