Wenbing Hou
commited on
Commit
•
d2e866b
1
Parent(s):
02a0f1b
Initial Commit
Browse files- app.py +34 -0
- pp_ocr.py +18 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from pp_ocr import inference_img, inference_json
|
4 |
+
|
5 |
+
title = "基于PP-OCRv3文本识别"
|
6 |
+
description = """
|
7 |
+
PaddleOCR是百度开源的超轻量级OCR模型库,提供了数十种文本检测、识别模型,旨在打造一套丰富、领先、实用的文字检测、识别模型/工具库。
|
8 |
+
> 项目地址:PaddleOCR github 地址: https://github.com/PaddlePaddle/PaddleOCR
|
9 |
+
"""
|
10 |
+
|
11 |
+
with gr.Blocks() as app:
|
12 |
+
gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>"
|
13 |
+
+ title
|
14 |
+
+ "</h1>")
|
15 |
+
gr.Markdown(description)
|
16 |
+
with gr.Tab("图片"):
|
17 |
+
with gr.Row():
|
18 |
+
with gr.Column():
|
19 |
+
img_input = gr.Image()
|
20 |
+
img_btn = gr.Button("识别")
|
21 |
+
with gr.Column():
|
22 |
+
img_output = gr.Image(label="Result")
|
23 |
+
with gr.Tab("JSON"):
|
24 |
+
with gr.Row():
|
25 |
+
with gr.Column():
|
26 |
+
json_input = gr.Image()
|
27 |
+
json_btn = gr.Button("识别")
|
28 |
+
with gr.Column():
|
29 |
+
json_output = gr.Json(label="Result")
|
30 |
+
|
31 |
+
img_btn.click(inference_img, inputs=img_input, outputs=img_output)
|
32 |
+
json_btn.click(inference_json, inputs=json_input, outputs=json_output)
|
33 |
+
|
34 |
+
app.launch()
|
pp_ocr.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tempfile
|
2 |
+
import os
|
3 |
+
|
4 |
+
import paddlehub as hub
|
5 |
+
from PIL import Image
|
6 |
+
|
7 |
+
pp_ocrv3 = hub.Module(name="ch_pp-ocrv3")
|
8 |
+
|
9 |
+
def inference_img(img):
|
10 |
+
with tempfile.TemporaryDirectory() as tempdir_name:
|
11 |
+
pp_ocrv3.recognize_text(images=[img], use_gpu=False, output_dir=tempdir_name, visualization=True)
|
12 |
+
result_names = os.listdir(tempdir_name)
|
13 |
+
result_image = Image.open(os.path.join(tempdir_name, result_names[0]))
|
14 |
+
return result_image
|
15 |
+
|
16 |
+
def inference_json(img):
|
17 |
+
results = pp_ocrv3.recognize_text(images=[img], use_gpu=False, visualization=False)
|
18 |
+
return results
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
paddlepaddle==2.4.2
|
2 |
+
paddlehub
|
3 |
+
gradio
|