File size: 1,771 Bytes
1d25e14
 
 
 
 
 
 
 
8fb0ef3
1d25e14
 
e077b28
bd3584b
1d25e14
e077b28
1d25e14
e077b28
1d25e14
 
93c3757
1d25e14
 
 
eeab14d
28085d0
1d25e14
 
 
 
 
 
 
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 os
os.system('pip install paddlepaddle')
os.system('pip install paddleocr')
from paddleocr import PaddleOCR, draw_ocr
from PIL import Image
import gradio as gr
import torch

torch.hub.download_url_to_file('https://i.imgur.com/dEcnZKX.png', 'muhammad_ali_wikipedia.png')

def inference(img, lang):
    ocr = PaddleOCR(lang=lang,use_gpu=False)
    result = ocr.ocr(img, cls=False)[0]
    txts = [line[1][0] for line in result]
    return "\n".join(txts)

title = 'PaddleOCR Extract Text'
description = 'Gradio demo for PaddleOCR. PaddleOCR demo supports Chinese, English, French, German, Korean and Japanese. To use it, simply upload your image and choose a language from the dropdown menu, or click one of the examples to load them. Read more at the links below.'
article = "<p style='text-align: center'><a href='https://www.paddlepaddle.org.cn/hub/scene/ocr'>Awesome multilingual OCR toolkits based on PaddlePaddle (practical ultra lightweight OCR system, support 80+ languages recognition, provide data annotation and synthesis tools, support training and deployment among server, mobile, embedded and IoT devices)</a> | <a href='https://github.com/PaddlePaddle/PaddleOCR'>Github Repo</a></p>"
examples = [['muhammad_ali_wikipedia.png','en']]
css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;}"
gr.Interface(
    inference,
    [gr.inputs.Image(type='filepath', label='Input'),gr.inputs.Dropdown(choices=['ch', 'en', 'fr', 'german', 'korean', 'japan'], type="value", default='en', label='language')],
    gr.outputs.Textbox(type="text", label="Text extracted from image"),
    title=title,
    description=description,
    article=article,
    examples=examples,
    css=css,
    enable_queue=True
    ).launch(debug=True)