Spaces:
Running
Running
Update app_gradio.py
Browse files- app_gradio.py +55 -14
app_gradio.py
CHANGED
@@ -2,21 +2,24 @@
|
|
2 |
# @Author: SWHL
|
3 |
# @Contact: [email protected]
|
4 |
import gradio as gr
|
|
|
5 |
|
|
|
6 |
|
7 |
-
def welcome(name):
|
8 |
-
return f"Welcome to Gradio, {name}!"
|
9 |
|
|
|
|
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
""
|
|
|
20 |
|
21 |
custom_css = """
|
22 |
body {font-family: body {font-family: 'Helvetica Neue', Helvetica;}
|
@@ -27,6 +30,7 @@ custom_css = """
|
|
27 |
.example-button:hover {background-color: #FF4500;}
|
28 |
.tall-radio .gr-radio-item {padding: 15px 0; min-height: 50px; display: flex; align-items: center;}
|
29 |
.tall-radio label {font-size: 16px;}
|
|
|
30 |
"""
|
31 |
|
32 |
with gr.Blocks(
|
@@ -46,9 +50,46 @@ with gr.Blocks(
|
|
46 |
</div>
|
47 |
"""
|
48 |
)
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
if __name__ == "__main__":
|
54 |
demo.launch(debug=True)
|
|
|
2 |
# @Author: SWHL
|
3 |
# @Contact: [email protected]
|
4 |
import gradio as gr
|
5 |
+
from PIL import Image
|
6 |
|
7 |
+
img_path = "images/1.jpg"
|
8 |
|
|
|
|
|
9 |
|
10 |
+
def test():
|
11 |
+
return Image.open(img_path)
|
12 |
|
13 |
+
|
14 |
+
example_images = [
|
15 |
+
"images/1.jpg",
|
16 |
+
"images/ch_en_num.jpg",
|
17 |
+
"images/air_ticket.jpg",
|
18 |
+
"images/car_plate.jpeg",
|
19 |
+
"images/train_ticket.jpeg",
|
20 |
+
"images/japan_2.jpg",
|
21 |
+
"images/korean_1.jpg",
|
22 |
+
]
|
23 |
|
24 |
custom_css = """
|
25 |
body {font-family: body {font-family: 'Helvetica Neue', Helvetica;}
|
|
|
30 |
.example-button:hover {background-color: #FF4500;}
|
31 |
.tall-radio .gr-radio-item {padding: 15px 0; min-height: 50px; display: flex; align-items: center;}
|
32 |
.tall-radio label {font-size: 16px;}
|
33 |
+
.output-image, .input-image, .image-preview {height: 300px !important}
|
34 |
"""
|
35 |
|
36 |
with gr.Blocks(
|
|
|
50 |
</div>
|
51 |
"""
|
52 |
)
|
53 |
+
with gr.Row():
|
54 |
+
text_score = gr.Slider(
|
55 |
+
label="text_score",
|
56 |
+
minimum=0,
|
57 |
+
maximum=1.0,
|
58 |
+
value=0.5,
|
59 |
+
step=0.1,
|
60 |
+
info="文本识别结果是正确的置信度,值越大,显示出的识别结果更准确。存在漏检时,调低该值。取值范围:[0, 1.0],默认值为0.5",
|
61 |
+
)
|
62 |
+
box_thresh = gr.Slider(
|
63 |
+
label="box_thresh",
|
64 |
+
minimum=0,
|
65 |
+
maximum=1.0,
|
66 |
+
value=0.5,
|
67 |
+
step=0.1,
|
68 |
+
info="检测到的框是文本的概率,值越大,框中是文本的概率就越大。存在漏检时,调低该值。取值范围:[0, 1.0],默认值为0.5",
|
69 |
+
)
|
70 |
+
unclip_ratio = gr.Slider(
|
71 |
+
label="unclip_ratio",
|
72 |
+
minimum=1.5,
|
73 |
+
maximum=2.0,
|
74 |
+
value=1.6,
|
75 |
+
step=0.1,
|
76 |
+
info="控制文本检测框的大小,值越大,检测框整体越大。在出现框截断文字的情况,调大该值。取值范围:[1.5, 2.0],默认值为1.6",
|
77 |
+
)
|
78 |
+
|
79 |
+
img_input = gr.Image(label="Upload or Select Image", sources="upload")
|
80 |
+
run_btn = gr.Button("Run")
|
81 |
+
|
82 |
+
run_btn.click(test, inputs=img_input, outputs=gr.Image())
|
83 |
+
|
84 |
+
examples = gr.Examples(
|
85 |
+
examples=example_images,
|
86 |
+
examples_per_page=len(example_images),
|
87 |
+
inputs=img_input,
|
88 |
+
fn=lambda x: x, # 简单返回图片路径
|
89 |
+
outputs=img_input,
|
90 |
+
cache_examples=False,
|
91 |
+
)
|
92 |
+
|
93 |
|
94 |
if __name__ == "__main__":
|
95 |
demo.launch(debug=True)
|