transformer-ocr / app.py
anhalu's picture
Create app.py
9a55fc0
raw
history blame
640 Bytes
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()