Update src/task.py file
Browse files- src/task.py +34 -33
src/task.py
CHANGED
@@ -1,33 +1,34 @@
|
|
1 |
-
import copy
|
2 |
-
from src.utils import
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
output_image =
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
1 |
+
import copy
|
2 |
+
from src.utils import clean_text, draw_ocr_bboxes
|
3 |
+
from src.model import run_example
|
4 |
+
|
5 |
+
|
6 |
+
def ocr_task(image):
|
7 |
+
"""
|
8 |
+
Perform OCR (Optical Character Recognition) on the given image.
|
9 |
+
|
10 |
+
Args:
|
11 |
+
image (PIL.Image.Image): The input image to perform OCR on.
|
12 |
+
|
13 |
+
Returns:
|
14 |
+
tuple: A tuple containing the output image with OCR bounding boxes drawn and the cleaned OCR text.
|
15 |
+
|
16 |
+
"""
|
17 |
+
|
18 |
+
# Task prompts
|
19 |
+
ocr_prompt = "<OCR>"
|
20 |
+
ocr_with_region_prompt = "<OCR_WITH_REGION>"
|
21 |
+
|
22 |
+
# Get OCR text
|
23 |
+
ocr_results = run_example(ocr_prompt, image)
|
24 |
+
cleaned_text = clean_text(ocr_results["<OCR>"])
|
25 |
+
|
26 |
+
# Get OCR with region
|
27 |
+
ocr_with_region_results = run_example(ocr_with_region_prompt, image)
|
28 |
+
output_image = copy.deepcopy(image)
|
29 |
+
output_image = draw_ocr_bboxes(
|
30 |
+
output_image, ocr_with_region_results["<OCR_WITH_REGION>"]
|
31 |
+
)
|
32 |
+
|
33 |
+
# Return the output image and cleaned OCR text
|
34 |
+
return output_image, cleaned_text
|