Spaces:
Running
on
Zero
Running
on
Zero
update
Browse files- app.py +21 -3
- data/logo.jpg +0 -0
app.py
CHANGED
@@ -40,6 +40,8 @@ def load_predictor(
|
|
40 |
reco_arch: str,
|
41 |
assume_straight_pages: bool,
|
42 |
straighten_pages: bool,
|
|
|
|
|
43 |
bin_thresh: float,
|
44 |
box_thresh: float,
|
45 |
) -> OCRPredictor:
|
@@ -51,6 +53,8 @@ def load_predictor(
|
|
51 |
reco_arch: recognition architecture
|
52 |
assume_straight_pages: whether to assume straight pages or not
|
53 |
straighten_pages: whether to straighten rotated pages or not
|
|
|
|
|
54 |
bin_thresh: binarization threshold for the segmentation map
|
55 |
box_thresh: minimal objectness score to consider a box
|
56 |
|
@@ -63,6 +67,8 @@ def load_predictor(
|
|
63 |
reco_arch,
|
64 |
assume_straight_pages=assume_straight_pages,
|
65 |
straighten_pages=straighten_pages,
|
|
|
|
|
66 |
export_as_straight_boxes=straighten_pages,
|
67 |
detect_orientation=not assume_straight_pages,
|
68 |
)
|
@@ -117,6 +123,8 @@ def analyze_page(
|
|
117 |
reco_arch: str,
|
118 |
assume_straight_pages: bool,
|
119 |
straighten_pages: bool,
|
|
|
|
|
120 |
bin_thresh: float,
|
121 |
box_thresh: float,
|
122 |
):
|
@@ -130,6 +138,8 @@ def analyze_page(
|
|
130 |
reco_arch: recognition architecture
|
131 |
assume_straight_pages: whether to assume straight pages or not
|
132 |
straighten_pages: whether to straighten rotated pages or not
|
|
|
|
|
133 |
bin_thresh: binarization threshold for the segmentation map
|
134 |
box_thresh: minimal objectness score to consider a box
|
135 |
|
@@ -153,6 +163,8 @@ def analyze_page(
|
|
153 |
reco_arch,
|
154 |
assume_straight_pages,
|
155 |
straighten_pages,
|
|
|
|
|
156 |
bin_thresh,
|
157 |
box_thresh,
|
158 |
)
|
@@ -173,8 +185,10 @@ def analyze_page(
|
|
173 |
|
174 |
|
175 |
with gr.Blocks(fill_height=True) as demo:
|
176 |
-
gr.
|
177 |
-
gr.
|
|
|
|
|
178 |
with gr.Row():
|
179 |
with gr.Column(scale=1):
|
180 |
upload = gr.File(label="Upload File [JPG | PNG | PDF]", file_types=["pdf", "jpg", "png"])
|
@@ -183,6 +197,8 @@ with gr.Blocks(fill_height=True) as demo:
|
|
183 |
reco_model = gr.Dropdown(choices=RECO_ARCHS, value=RECO_ARCHS[0], label="Text recognition model")
|
184 |
assume_straight = gr.Checkbox(value=True, label="Assume straight pages")
|
185 |
straighten = gr.Checkbox(value=False, label="Straighten pages")
|
|
|
|
|
186 |
binarization_threshold = gr.Slider(
|
187 |
minimum=0.1, maximum=0.9, value=0.3, step=0.1, label="Binarization threshold"
|
188 |
)
|
@@ -208,10 +224,12 @@ with gr.Blocks(fill_height=True) as demo:
|
|
208 |
reco_model,
|
209 |
assume_straight,
|
210 |
straighten,
|
|
|
|
|
211 |
binarization_threshold,
|
212 |
box_threshold,
|
213 |
],
|
214 |
outputs=[input_image, segmentation_heatmap, output_image, ocr_output],
|
215 |
)
|
216 |
|
217 |
-
demo.launch(inbrowser=True)
|
|
|
40 |
reco_arch: str,
|
41 |
assume_straight_pages: bool,
|
42 |
straighten_pages: bool,
|
43 |
+
detect_language: bool,
|
44 |
+
load_in_8_bit: bool,
|
45 |
bin_thresh: float,
|
46 |
box_thresh: float,
|
47 |
) -> OCRPredictor:
|
|
|
53 |
reco_arch: recognition architecture
|
54 |
assume_straight_pages: whether to assume straight pages or not
|
55 |
straighten_pages: whether to straighten rotated pages or not
|
56 |
+
detect_language: whether to detect the language of the text
|
57 |
+
load_in_8_bit: whether to load the image in 8 bit mode
|
58 |
bin_thresh: binarization threshold for the segmentation map
|
59 |
box_thresh: minimal objectness score to consider a box
|
60 |
|
|
|
67 |
reco_arch,
|
68 |
assume_straight_pages=assume_straight_pages,
|
69 |
straighten_pages=straighten_pages,
|
70 |
+
detect_language=detect_language,
|
71 |
+
load_in_8_bit=load_in_8_bit,
|
72 |
export_as_straight_boxes=straighten_pages,
|
73 |
detect_orientation=not assume_straight_pages,
|
74 |
)
|
|
|
123 |
reco_arch: str,
|
124 |
assume_straight_pages: bool,
|
125 |
straighten_pages: bool,
|
126 |
+
detect_language: bool,
|
127 |
+
load_in_8_bit: bool,
|
128 |
bin_thresh: float,
|
129 |
box_thresh: float,
|
130 |
):
|
|
|
138 |
reco_arch: recognition architecture
|
139 |
assume_straight_pages: whether to assume straight pages or not
|
140 |
straighten_pages: whether to straighten rotated pages or not
|
141 |
+
detect_language: whether to detect the language of the text
|
142 |
+
load_in_8_bit: whether to load the image in 8 bit mode
|
143 |
bin_thresh: binarization threshold for the segmentation map
|
144 |
box_thresh: minimal objectness score to consider a box
|
145 |
|
|
|
163 |
reco_arch,
|
164 |
assume_straight_pages,
|
165 |
straighten_pages,
|
166 |
+
detect_language,
|
167 |
+
load_in_8_bit,
|
168 |
bin_thresh,
|
169 |
box_thresh,
|
170 |
)
|
|
|
185 |
|
186 |
|
187 |
with gr.Blocks(fill_height=True) as demo:
|
188 |
+
#gr.Image("/file=data/logo.jpg", height=400, label=None, show_label=False, show_download_button=False)
|
189 |
+
gr.HTML("<h1>OnnxTR OCR Demo</h1>")
|
190 |
+
gr.HTML("<h2>GitHub: <a href='https://github.com/felixdittrich92/OnnxTR'>OnnxTR</a></h2>")
|
191 |
+
gr.HTML("</div>")
|
192 |
with gr.Row():
|
193 |
with gr.Column(scale=1):
|
194 |
upload = gr.File(label="Upload File [JPG | PNG | PDF]", file_types=["pdf", "jpg", "png"])
|
|
|
197 |
reco_model = gr.Dropdown(choices=RECO_ARCHS, value=RECO_ARCHS[0], label="Text recognition model")
|
198 |
assume_straight = gr.Checkbox(value=True, label="Assume straight pages")
|
199 |
straighten = gr.Checkbox(value=False, label="Straighten pages")
|
200 |
+
det_language = gr.Checkbox(value=False, label="Detect language")
|
201 |
+
load_in_8_bit = gr.Checkbox(value=False, label="Load 8-bit quantized models")
|
202 |
binarization_threshold = gr.Slider(
|
203 |
minimum=0.1, maximum=0.9, value=0.3, step=0.1, label="Binarization threshold"
|
204 |
)
|
|
|
224 |
reco_model,
|
225 |
assume_straight,
|
226 |
straighten,
|
227 |
+
det_language,
|
228 |
+
load_in_8_bit,
|
229 |
binarization_threshold,
|
230 |
box_threshold,
|
231 |
],
|
232 |
outputs=[input_image, segmentation_heatmap, output_image, ocr_output],
|
233 |
)
|
234 |
|
235 |
+
demo.launch(inbrowser=True, allowed_paths=['./data/logo.jpg'])
|
data/logo.jpg
ADDED