Spaces:
Running
on
Zero
Running
on
Zero
Add 0.5.0 features
Browse files
app.py
CHANGED
@@ -44,6 +44,8 @@ def load_predictor(
|
|
44 |
load_in_8_bit: bool,
|
45 |
bin_thresh: float,
|
46 |
box_thresh: float,
|
|
|
|
|
47 |
) -> OCRPredictor:
|
48 |
"""Load a predictor from doctr.models
|
49 |
|
@@ -52,6 +54,8 @@ def load_predictor(
|
|
52 |
det_arch: detection architecture
|
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
|
@@ -71,6 +75,8 @@ def load_predictor(
|
|
71 |
load_in_8_bit=load_in_8_bit,
|
72 |
export_as_straight_boxes=straighten_pages,
|
73 |
detect_orientation=not assume_straight_pages,
|
|
|
|
|
74 |
)
|
75 |
predictor.det_predictor.model.postprocessor.bin_thresh = bin_thresh
|
76 |
predictor.det_predictor.model.postprocessor.box_thresh = box_thresh
|
@@ -122,6 +128,8 @@ def analyze_page(
|
|
122 |
det_arch: str,
|
123 |
reco_arch: str,
|
124 |
assume_straight_pages: bool,
|
|
|
|
|
125 |
straighten_pages: bool,
|
126 |
detect_language: bool,
|
127 |
load_in_8_bit: bool,
|
@@ -137,6 +145,8 @@ def analyze_page(
|
|
137 |
det_arch: detection architecture
|
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
|
@@ -167,6 +177,8 @@ def analyze_page(
|
|
167 |
load_in_8_bit,
|
168 |
bin_thresh,
|
169 |
box_thresh,
|
|
|
|
|
170 |
)
|
171 |
|
172 |
seg_map = forward_image(predictor, page)
|
@@ -215,6 +227,8 @@ with gr.Blocks(fill_height=True) as demo:
|
|
215 |
det_model = gr.Dropdown(choices=DET_ARCHS, value=DET_ARCHS[0], label="Text detection model")
|
216 |
reco_model = gr.Dropdown(choices=RECO_ARCHS, value=RECO_ARCHS[0], label="Text recognition model")
|
217 |
assume_straight = gr.Checkbox(value=True, label="Assume straight pages")
|
|
|
|
|
218 |
straighten = gr.Checkbox(value=False, label="Straighten pages")
|
219 |
det_language = gr.Checkbox(value=False, label="Detect language")
|
220 |
load_in_8_bit = gr.Checkbox(value=False, label="Load 8-bit quantized models")
|
@@ -242,6 +256,8 @@ with gr.Blocks(fill_height=True) as demo:
|
|
242 |
det_model,
|
243 |
reco_model,
|
244 |
assume_straight,
|
|
|
|
|
245 |
straighten,
|
246 |
det_language,
|
247 |
load_in_8_bit,
|
|
|
44 |
load_in_8_bit: bool,
|
45 |
bin_thresh: float,
|
46 |
box_thresh: float,
|
47 |
+
disable_crop_orientation: bool = False,
|
48 |
+
disable_page_orientation: bool = False,
|
49 |
) -> OCRPredictor:
|
50 |
"""Load a predictor from doctr.models
|
51 |
|
|
|
54 |
det_arch: detection architecture
|
55 |
reco_arch: recognition architecture
|
56 |
assume_straight_pages: whether to assume straight pages or not
|
57 |
+
disable_crop_orientation: whether to disable crop orientation or not
|
58 |
+
disable_page_orientation: whether to disable page orientation or not
|
59 |
straighten_pages: whether to straighten rotated pages or not
|
60 |
detect_language: whether to detect the language of the text
|
61 |
load_in_8_bit: whether to load the image in 8 bit mode
|
|
|
75 |
load_in_8_bit=load_in_8_bit,
|
76 |
export_as_straight_boxes=straighten_pages,
|
77 |
detect_orientation=not assume_straight_pages,
|
78 |
+
disable_crop_orientation=disable_crop_orientation,
|
79 |
+
disable_page_orientation=disable_page_orientation,
|
80 |
)
|
81 |
predictor.det_predictor.model.postprocessor.bin_thresh = bin_thresh
|
82 |
predictor.det_predictor.model.postprocessor.box_thresh = box_thresh
|
|
|
128 |
det_arch: str,
|
129 |
reco_arch: str,
|
130 |
assume_straight_pages: bool,
|
131 |
+
disable_crop_orientation: bool,
|
132 |
+
disable_page_orientation: bool,
|
133 |
straighten_pages: bool,
|
134 |
detect_language: bool,
|
135 |
load_in_8_bit: bool,
|
|
|
145 |
det_arch: detection architecture
|
146 |
reco_arch: recognition architecture
|
147 |
assume_straight_pages: whether to assume straight pages or not
|
148 |
+
disable_crop_orientation: whether to disable crop orientation or not
|
149 |
+
disable_page_orientation: whether to disable page orientation or not
|
150 |
straighten_pages: whether to straighten rotated pages or not
|
151 |
detect_language: whether to detect the language of the text
|
152 |
load_in_8_bit: whether to load the image in 8 bit mode
|
|
|
177 |
load_in_8_bit,
|
178 |
bin_thresh,
|
179 |
box_thresh,
|
180 |
+
disable_crop_orientation=disable_crop_orientation,
|
181 |
+
disable_page_orientation=disable_page_orientation,
|
182 |
)
|
183 |
|
184 |
seg_map = forward_image(predictor, page)
|
|
|
227 |
det_model = gr.Dropdown(choices=DET_ARCHS, value=DET_ARCHS[0], label="Text detection model")
|
228 |
reco_model = gr.Dropdown(choices=RECO_ARCHS, value=RECO_ARCHS[0], label="Text recognition model")
|
229 |
assume_straight = gr.Checkbox(value=True, label="Assume straight pages")
|
230 |
+
disable_crop_orientation = gr.Checkbox(value=False, label="Disable crop orientation")
|
231 |
+
disable_page_orientation = gr.Checkbox(value=False, label="Disable page orientation")
|
232 |
straighten = gr.Checkbox(value=False, label="Straighten pages")
|
233 |
det_language = gr.Checkbox(value=False, label="Detect language")
|
234 |
load_in_8_bit = gr.Checkbox(value=False, label="Load 8-bit quantized models")
|
|
|
256 |
det_model,
|
257 |
reco_model,
|
258 |
assume_straight,
|
259 |
+
disable_crop_orientation,
|
260 |
+
disable_page_orientation,
|
261 |
straighten,
|
262 |
det_language,
|
263 |
load_in_8_bit,
|