Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,6 +12,7 @@ from dotenv import load_dotenv
|
|
| 12 |
# OCR Imports (EasyOCR)
|
| 13 |
import easyocr
|
| 14 |
from pdf2image import convert_from_bytes
|
|
|
|
| 15 |
|
| 16 |
app = Flask(__name__)
|
| 17 |
CORS(app, resources={r"/*": {"origins": "*"}})
|
|
@@ -91,17 +92,18 @@ def extract_text_with_pypdf2(pdf_file):
|
|
| 91 |
|
| 92 |
|
| 93 |
def extract_text_with_easyocr(pdf_bytes):
|
| 94 |
-
"""Extract text from scanned PDF using EasyOCR."""
|
| 95 |
images = convert_from_bytes(pdf_bytes, dpi=150)
|
| 96 |
full_text = ""
|
| 97 |
|
| 98 |
for img in images:
|
| 99 |
-
|
|
|
|
| 100 |
result = easyocr_reader.readtext(
|
| 101 |
-
|
| 102 |
detail=0,
|
| 103 |
paragraph=True
|
| 104 |
)
|
|
|
|
| 105 |
full_text += "\n".join(result) + "\n"
|
| 106 |
|
| 107 |
return full_text.strip()
|
|
|
|
| 12 |
# OCR Imports (EasyOCR)
|
| 13 |
import easyocr
|
| 14 |
from pdf2image import convert_from_bytes
|
| 15 |
+
import numpy as np
|
| 16 |
|
| 17 |
app = Flask(__name__)
|
| 18 |
CORS(app, resources={r"/*": {"origins": "*"}})
|
|
|
|
| 92 |
|
| 93 |
|
| 94 |
def extract_text_with_easyocr(pdf_bytes):
|
|
|
|
| 95 |
images = convert_from_bytes(pdf_bytes, dpi=150)
|
| 96 |
full_text = ""
|
| 97 |
|
| 98 |
for img in images:
|
| 99 |
+
img_np = np.array(img) # PIL -> numpy array
|
| 100 |
+
|
| 101 |
result = easyocr_reader.readtext(
|
| 102 |
+
img_np,
|
| 103 |
detail=0,
|
| 104 |
paragraph=True
|
| 105 |
)
|
| 106 |
+
|
| 107 |
full_text += "\n".join(result) + "\n"
|
| 108 |
|
| 109 |
return full_text.strip()
|