Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -18,36 +18,16 @@ class InferEngine(Enum):
|
|
18 |
|
19 |
|
20 |
def get_ocr_engine(infer_engine: str, lang_det: str, lang_rec: str) -> RapidOCR:
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
}
|
28 |
-
)
|
29 |
-
|
30 |
-
if infer_engine == InferEngine.paddle.value:
|
31 |
-
return RapidOCR(
|
32 |
-
params={
|
33 |
-
"Global.with_paddle": True,
|
34 |
-
"Global.lang_det": lang_det,
|
35 |
-
"Global.lang_rec": lang_rec,
|
36 |
-
}
|
37 |
-
)
|
38 |
-
|
39 |
-
if infer_engine == InferEngine.torch.value:
|
40 |
-
return RapidOCR(
|
41 |
-
params={
|
42 |
-
"Global.with_torch": True,
|
43 |
-
"Global.lang_det": lang_det,
|
44 |
-
"Global.lang_rec": lang_rec,
|
45 |
-
}
|
46 |
-
)
|
47 |
|
48 |
return RapidOCR(
|
49 |
params={
|
50 |
-
"Global.
|
51 |
"Global.lang_det": lang_det,
|
52 |
"Global.lang_rec": lang_rec,
|
53 |
}
|
@@ -89,68 +69,24 @@ def get_ocr_result(
|
|
89 |
|
90 |
|
91 |
def create_examples() -> List[List[Union[str, float]]]:
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
"No",
|
102 |
-
],
|
103 |
-
[
|
104 |
-
"images/japan.jpg",
|
105 |
-
0.5,
|
106 |
-
0.5,
|
107 |
-
1.6,
|
108 |
-
"multi_mobile",
|
109 |
-
"japan_mobile",
|
110 |
-
"ONNXRuntime",
|
111 |
-
"No",
|
112 |
-
],
|
113 |
-
[
|
114 |
-
"images/korean.jpg",
|
115 |
-
0.5,
|
116 |
-
0.5,
|
117 |
-
1.6,
|
118 |
-
"multi_mobile",
|
119 |
-
"korean_mobile",
|
120 |
-
"ONNXRuntime",
|
121 |
-
"No",
|
122 |
-
],
|
123 |
-
[
|
124 |
-
"images/air_ticket.jpg",
|
125 |
-
0.5,
|
126 |
-
0.5,
|
127 |
-
1.6,
|
128 |
-
"ch_mobile",
|
129 |
-
"ch_mobile",
|
130 |
-
"ONNXRuntime",
|
131 |
-
"No",
|
132 |
-
],
|
133 |
-
[
|
134 |
-
"images/car_plate.jpeg",
|
135 |
-
0.5,
|
136 |
-
0.5,
|
137 |
-
1.6,
|
138 |
-
"ch_mobile",
|
139 |
-
"ch_mobile",
|
140 |
-
"ONNXRuntime",
|
141 |
-
"No",
|
142 |
-
],
|
143 |
-
[
|
144 |
-
"images/train_ticket.jpeg",
|
145 |
-
0.5,
|
146 |
-
0.5,
|
147 |
-
1.6,
|
148 |
-
"ch_mobile",
|
149 |
-
"ch_mobile",
|
150 |
-
"ONNXRuntime",
|
151 |
-
"No",
|
152 |
-
],
|
153 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
return examples
|
155 |
|
156 |
|
|
|
18 |
|
19 |
|
20 |
def get_ocr_engine(infer_engine: str, lang_det: str, lang_rec: str) -> RapidOCR:
|
21 |
+
engine_mapping = {
|
22 |
+
InferEngine.vino.value: "with_openvino",
|
23 |
+
InferEngine.paddle.value: "with_paddle",
|
24 |
+
InferEngine.torch.value: "with_torch",
|
25 |
+
}
|
26 |
+
param_key = engine_mapping.get(infer_engine, "with_onnx")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
return RapidOCR(
|
29 |
params={
|
30 |
+
f"Global.{param_key}": True,
|
31 |
"Global.lang_det": lang_det,
|
32 |
"Global.lang_rec": lang_rec,
|
33 |
}
|
|
|
69 |
|
70 |
|
71 |
def create_examples() -> List[List[Union[str, float]]]:
|
72 |
+
DEFAULT_VALUES = [0.5, 0.5, 1.6, "ch_mobile", "ch_mobile", "ONNXRuntime", "No"]
|
73 |
+
|
74 |
+
image_specs = [
|
75 |
+
("images/ch_en_num.jpg", {}),
|
76 |
+
("images/japan.jpg", {3: "multi_mobile", 4: "japan_mobile"}),
|
77 |
+
("images/korean.jpg", {3: "multi_mobile", 4: "korean_mobile"}),
|
78 |
+
("images/air_ticket.jpg", {}),
|
79 |
+
("images/car_plate.jpeg", {}),
|
80 |
+
("images/train_ticket.jpeg", {}),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
]
|
82 |
+
|
83 |
+
examples = []
|
84 |
+
for image_path, overrides in image_specs:
|
85 |
+
example = DEFAULT_VALUES.copy()
|
86 |
+
example.insert(0, image_path)
|
87 |
+
for index, value in overrides.items():
|
88 |
+
example[index + 1] = value
|
89 |
+
examples.append(example)
|
90 |
return examples
|
91 |
|
92 |
|