ishworrsubedii
commited on
Update src/services/ocr/replicate_ocr/replicate_ocr.py
Browse files
src/services/ocr/replicate_ocr/replicate_ocr.py
CHANGED
@@ -4,6 +4,8 @@ created @ 2024-11-06
|
|
4 |
author @ github.com/ishworrsubedii
|
5 |
"""
|
6 |
import base64
|
|
|
|
|
7 |
import numpy as np
|
8 |
import replicate
|
9 |
|
@@ -20,16 +22,15 @@ class ReplicateOCR:
|
|
20 |
def __init__(self):
|
21 |
pass
|
22 |
|
23 |
-
def read_text(self, image_path
|
24 |
-
|
25 |
-
|
26 |
|
27 |
-
input_image_uri= f"data:image/png;base64,{base_64_image}"
|
28 |
input = {
|
29 |
"image": input_image_uri,
|
30 |
}
|
31 |
output = replicate_run(input)
|
32 |
output = output.replace("\n", " ").replace("\t", " ")
|
33 |
|
34 |
-
|
35 |
-
return output
|
|
|
4 |
author @ github.com/ishworrsubedii
|
5 |
"""
|
6 |
import base64
|
7 |
+
|
8 |
+
import cv2
|
9 |
import numpy as np
|
10 |
import replicate
|
11 |
|
|
|
22 |
def __init__(self):
|
23 |
pass
|
24 |
|
25 |
+
def read_text(self, image_path):
|
26 |
+
_, buffer = cv2.imencode('.png', image_path)
|
27 |
+
base_64_image = base64.b64encode(buffer).decode('utf-8')
|
28 |
|
29 |
+
input_image_uri = f"data:image/png;base64,{base_64_image}"
|
30 |
input = {
|
31 |
"image": input_image_uri,
|
32 |
}
|
33 |
output = replicate_run(input)
|
34 |
output = output.replace("\n", " ").replace("\t", " ")
|
35 |
|
36 |
+
return output
|
|