Spaces:
Sleeping
Sleeping
Update tools/ocr.py
Browse files- tools/ocr.py +12 -0
tools/ocr.py
CHANGED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
def ocr_tool(image_path: str) -> str:
|
2 |
+
"""Extracts text from images or scanned documents using OCR.
|
3 |
+
Args:
|
4 |
+
image_path: Path to the image file
|
5 |
+
"""
|
6 |
+
try:
|
7 |
+
ocr_engine = PaddleOCR(use_angle_cls=True, lang='en')
|
8 |
+
result = ocr_engine.ocr(image_path, cls=True)
|
9 |
+
texts = [line[1][0] for line in result[0]] if result else []
|
10 |
+
return "\n".join(texts)
|
11 |
+
except Exception as e:
|
12 |
+
return f"OCR Error: {str(e)}"
|