sitammeur commited on
Commit
5f74261
1 Parent(s): 318055c

Update src/task.py file

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