Spaces:
Runtime error
Runtime error
Commit
·
e077b28
1
Parent(s):
1d25e14
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,20 +9,13 @@ import torch
|
|
| 9 |
torch.hub.download_url_to_file('https://i.imgur.com/aqMBT0i.jpg', 'example.jpg')
|
| 10 |
|
| 11 |
def inference(img, lang):
|
| 12 |
-
ocr = PaddleOCR(
|
| 13 |
img_path = img.name
|
| 14 |
-
result = ocr.ocr(img_path, cls=
|
| 15 |
-
image = Image.open(img_path).convert('RGB')
|
| 16 |
-
boxes = [line[0] for line in result]
|
| 17 |
txts = [line[1][0] for line in result]
|
| 18 |
-
|
| 19 |
-
im_show = draw_ocr(image, boxes, txts, scores,
|
| 20 |
-
font_path='simfang.ttf')
|
| 21 |
-
im_show = Image.fromarray(im_show)
|
| 22 |
-
im_show.save('result.jpg')
|
| 23 |
-
return 'result.jpg'
|
| 24 |
|
| 25 |
-
title = 'PaddleOCR'
|
| 26 |
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.'
|
| 27 |
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>"
|
| 28 |
examples = [['example.jpg','en']]
|
|
@@ -30,7 +23,7 @@ css = ".output_image, .input_image {height: 40rem !important; width: 100% !impor
|
|
| 30 |
gr.Interface(
|
| 31 |
inference,
|
| 32 |
[gr.inputs.Image(type='file', label='Input'),gr.inputs.Dropdown(choices=['ch', 'en', 'fr', 'german', 'korean', 'japan'], type="value", default='en', label='language')],
|
| 33 |
-
gr.outputs.
|
| 34 |
title=title,
|
| 35 |
description=description,
|
| 36 |
article=article,
|
|
|
|
| 9 |
torch.hub.download_url_to_file('https://i.imgur.com/aqMBT0i.jpg', 'example.jpg')
|
| 10 |
|
| 11 |
def inference(img, lang):
|
| 12 |
+
ocr = PaddleOCR(lang=lang,use_gpu=False)
|
| 13 |
img_path = img.name
|
| 14 |
+
result = ocr.ocr(img_path, cls=False)[0]
|
|
|
|
|
|
|
| 15 |
txts = [line[1][0] for line in result]
|
| 16 |
+
return "\n".join(txts)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
title = 'PaddleOCR Extract Text'
|
| 19 |
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.'
|
| 20 |
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>"
|
| 21 |
examples = [['example.jpg','en']]
|
|
|
|
| 23 |
gr.Interface(
|
| 24 |
inference,
|
| 25 |
[gr.inputs.Image(type='file', label='Input'),gr.inputs.Dropdown(choices=['ch', 'en', 'fr', 'german', 'korean', 'japan'], type="value", default='en', label='language')],
|
| 26 |
+
gr.outputs.Textbox(type="auto", label="Text extracted from image"),
|
| 27 |
title=title,
|
| 28 |
description=description,
|
| 29 |
article=article,
|