Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -225,14 +225,6 @@ def get_page_md_and_regions(page_result):
|
|
| 225 |
return md, regions
|
| 226 |
|
| 227 |
|
| 228 |
-
def is_duplicate(text, existing_text):
|
| 229 |
-
"""Check if text is already contained in existing_text using first 100 chars as fingerprint."""
|
| 230 |
-
if not text or not existing_text:
|
| 231 |
-
return False
|
| 232 |
-
fingerprint = text[:100].strip()
|
| 233 |
-
return fingerprint in existing_text
|
| 234 |
-
|
| 235 |
-
|
| 236 |
def run_ocr(uploaded_file):
|
| 237 |
if uploaded_file is None:
|
| 238 |
return "Please upload a file."
|
|
@@ -301,8 +293,7 @@ def run_ocr(uploaded_file):
|
|
| 301 |
ftr = extract_pdf_text_in_band(path, page_num, PDF_FOOTER_BAND_FRAC, 1.0)
|
| 302 |
if not (ftr and ftr.strip()):
|
| 303 |
ftr = ocr_zone(img_path, fs, 1.0)
|
| 304 |
-
|
| 305 |
-
if ftr and ftr.strip() and not is_duplicate(ftr, page_md):
|
| 306 |
parts.append(ftr.strip())
|
| 307 |
|
| 308 |
if parts:
|
|
@@ -323,4 +314,4 @@ with gr.Blocks(title="GLM-OCR") as demo:
|
|
| 323 |
run_btn.click(fn=run_ocr, inputs=file_in, outputs=out)
|
| 324 |
|
| 325 |
if __name__ == "__main__":
|
| 326 |
-
demo.launch()
|
|
|
|
| 225 |
return md, regions
|
| 226 |
|
| 227 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
def run_ocr(uploaded_file):
|
| 229 |
if uploaded_file is None:
|
| 230 |
return "Please upload a file."
|
|
|
|
| 293 |
ftr = extract_pdf_text_in_band(path, page_num, PDF_FOOTER_BAND_FRAC, 1.0)
|
| 294 |
if not (ftr and ftr.strip()):
|
| 295 |
ftr = ocr_zone(img_path, fs, 1.0)
|
| 296 |
+
if ftr and ftr.strip():
|
|
|
|
| 297 |
parts.append(ftr.strip())
|
| 298 |
|
| 299 |
if parts:
|
|
|
|
| 314 |
run_btn.click(fn=run_ocr, inputs=file_in, outputs=out)
|
| 315 |
|
| 316 |
if __name__ == "__main__":
|
| 317 |
+
demo.launch()
|