Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import glob
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from demo import get_model, preprocess, postprocess, load
|
| 4 |
+
from utils import Config, Logger, CharsetMapper
|
| 5 |
+
|
| 6 |
+
config = Config('configs/train_iternet.yaml')
|
| 7 |
+
config.model_vision_checkpoint = None
|
| 8 |
+
model = get_model(config)
|
| 9 |
+
model = load(model, 'workdir/train-iternet/best-train-iternet.pth')
|
| 10 |
+
charset = CharsetMapper(filename=config.dataset_charset_path, max_length=config.dataset_max_length + 1)
|
| 11 |
+
|
| 12 |
+
def process_image(image):
|
| 13 |
+
img = image.convert('RGB')
|
| 14 |
+
img = preprocess(img, config.dataset_image_width, config.dataset_image_height)
|
| 15 |
+
res = model(img)
|
| 16 |
+
return postprocess(res, charset, 'alignment')[0][0]
|
| 17 |
+
|
| 18 |
+
title = "Interactive demo: ABINet"
|
| 19 |
+
description = "Demo for ABINet, ABINet uses a vision model and an explicit language model to recognize text in the wild, which are trained in end-to-end way. The language model (BCN) achieves bidirectional language representation in simulating cloze test, additionally utilizing iterative correction strategy. To use it, simply upload a (single-text line) image or use one of the example images below and click 'submit'. Results will show up in a few seconds."
|
| 20 |
+
article = "<p style='text-align: center'><a href='https://arxiv.org/pdf/2103.06495.pdf'>Read Like Humans: Autonomous, Bidirectional and Iterative Language Modeling for Scene Text Recognition</a> | <a href='https://github.com/FangShancheng/ABINet'>Github Repo</a></p>"
|
| 21 |
+
|
| 22 |
+
iface = gr.Interface(fn=process_image,
|
| 23 |
+
inputs=gr.inputs.Image(type="pil"),
|
| 24 |
+
outputs=gr.outputs.Textbox(),
|
| 25 |
+
title=title,
|
| 26 |
+
description=description,
|
| 27 |
+
article=article,
|
| 28 |
+
examples=glob.glob('figs/test/*.png'))
|
| 29 |
+
|
| 30 |
+
iface.launch(debug=True, share=True,enable_queue=True)
|