File size: 3,721 Bytes
a0112f4
 
 
 
ccac0de
a0112f4
ccac0de
a0112f4
 
ccac0de
 
a0112f4
ccac0de
 
 
 
 
 
 
 
 
 
a0112f4
 
 
 
 
 
 
 
 
 
ccac0de
a0112f4
 
 
 
 
 
86f1fd6
 
 
 
 
 
 
 
 
 
 
 
a0112f4
ccac0de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a0112f4
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# -*- encoding: utf-8 -*-
# @Author: SWHL
# @Contact: [email protected]
import gradio as gr
from PIL import Image

img_path = "images/1.jpg"


def test():
    return Image.open(img_path)


example_images = [
    "images/1.jpg",
    "images/ch_en_num.jpg",
    "images/air_ticket.jpg",
    "images/car_plate.jpeg",
    "images/train_ticket.jpeg",
    "images/japan_2.jpg",
    "images/korean_1.jpg",
]

custom_css = """
    body {font-family: body {font-family: 'Helvetica Neue', Helvetica;}
    .gr-button {background-color: #4CAF50; color: white; border: none; padding: 10px 20px; border-radius: 5px;}
    .gr-button:hover {background-color: #45a049;}
    .gr-textbox {margin-bottom: 15px;}
    .example-button {background-color: #1E90FF; color: white; border: none; padding: 8px 15px; border-radius: 5px; margin: 5px;}
    .example-button:hover {background-color: #FF4500;}
    .tall-radio .gr-radio-item {padding: 15px 0; min-height: 50px; display: flex; align-items: center;}
    .tall-radio label {font-size: 16px;}
    .output-image, .input-image, .image-preview {height: 300px !important}
"""

with gr.Blocks(
    title="Rapid⚡OCR Demo", css="custom_css", theme=gr.themes.Soft()
) as demo:
    gr.Markdown(
        "<h1 style='text-align: center;'><a href='https://rapidai.github.io/RapidOCRDocs/' style='text-decoration: none;'>Rapid⚡OCR</a></h1>"
    )
    gr.HTML(
        """
        <div style="display: flex; justify-content: center; gap: 10px;">
            <a href=""><img src="https://img.shields.io/badge/Python->=3.6-aff.svg"></a>
            <a href=""><img src="https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-pink.svg"></a>
            <a href="https://pepy.tech/project/rapidocr"><img src="https://static.pepy.tech/personalized-badge/rapidocr?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=Downloads%20rapidocr"></a>
            <a href="https://pypi.org/project/rapidocr/"><img alt="PyPI" src="https://img.shields.io/pypi/v/rapidocr"></a>
            <a href="https://github.com/RapidAI/RapidOCR"><img src="https://img.shields.io/github/stars/RapidAI/RapidOCR?color=ccf"></a>
        </div>
    """
    )
    with gr.Row():
        text_score = gr.Slider(
            label="text_score",
            minimum=0,
            maximum=1.0,
            value=0.5,
            step=0.1,
            info="文本识别结果是正确的置信度,值越大,显示出的识别结果更准确。存在漏检时,调低该值。取值范围:[0, 1.0],默认值为0.5",
        )
        box_thresh = gr.Slider(
            label="box_thresh",
            minimum=0,
            maximum=1.0,
            value=0.5,
            step=0.1,
            info="检测到的框是文本的概率,值越大,框中是文本的概率就越大。存在漏检时,调低该值。取值范围:[0, 1.0],默认值为0.5",
        )
        unclip_ratio = gr.Slider(
            label="unclip_ratio",
            minimum=1.5,
            maximum=2.0,
            value=1.6,
            step=0.1,
            info="控制文本检测框的大小,值越大,检测框整体越大。在出现框截断文字的情况,调大该值。取值范围:[1.5, 2.0],默认值为1.6",
        )

    img_input = gr.Image(label="Upload or Select Image", sources="upload")
    run_btn = gr.Button("Run")

    run_btn.click(test, inputs=img_input, outputs=gr.Image())

    examples = gr.Examples(
        examples=example_images,
        examples_per_page=len(example_images),
        inputs=img_input,
        fn=lambda x: x,  # 简单返回图片路径
        outputs=img_input,
        cache_examples=False,
    )


if __name__ == "__main__":
    demo.launch(debug=True)