Atulit23 commited on
Commit
6488435
·
verified ·
1 Parent(s): 548b363

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -37,3 +37,4 @@ en_PP-OCRv3_det_infer/inference.pdiparams filter=lfs diff=lfs merge=lfs -text
37
  en_PP-OCRv3_det_infer/inference.pdmodel filter=lfs diff=lfs merge=lfs -text
38
  en_PP-OCRv3_rec_infer/inference.pdiparams filter=lfs diff=lfs merge=lfs -text
39
  en_PP-OCRv3_rec_infer/inference.pdmodel filter=lfs diff=lfs merge=lfs -text
 
 
37
  en_PP-OCRv3_det_infer/inference.pdmodel filter=lfs diff=lfs merge=lfs -text
38
  en_PP-OCRv3_rec_infer/inference.pdiparams filter=lfs diff=lfs merge=lfs -text
39
  en_PP-OCRv3_rec_infer/inference.pdmodel filter=lfs diff=lfs merge=lfs -text
40
+ tesseract-ocr-w64-setup-5.3.3.20231005.exe filter=lfs diff=lfs merge=lfs -text
app.py CHANGED
@@ -1,39 +1,53 @@
1
- from paddleocr import PaddleOCR
2
- import requests
3
  import numpy as np
4
- from PIL import Image
5
- from io import BytesIO
6
  import json
7
  import gradio as gr
8
- import paddleocr
 
 
9
 
10
  # ocr = PaddleOCR(use_angle_cls=True, lang='en', use_pdserving=False, cls_batch_num=8, det_batch_num=8, rec_batch_num=8)
11
 
12
- ocr = PaddleOCR(use_angle_cls=True, lang='en')
13
 
14
- def index(url):
15
- response = requests.get(url)
16
- img = Image.open(BytesIO(response.content))
17
- resize_factor = 1
18
- new_size = tuple(int(dim * resize_factor) for dim in img.size)
19
- img = img.resize(new_size, Image.Resampling.LANCZOS)
20
 
21
- img_array = np.array(img.convert('RGB'))
22
 
23
- result = ocr.ocr(img_array)
24
 
25
- boxes = [line[0] for line in result]
26
- txts = [line[1][0] for line in result]
27
- scores = [line[1][1] for line in result]
28
 
29
- print(boxes)
30
- print(txts)
31
 
32
- output_dict = {"texts": txts, "boxes": boxes, "scores": scores}
33
- output_json = json.dumps(output_dict) # Convert to JSON string
34
 
35
- return output_json
 
 
 
 
36
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
  inputs_image_url = [
39
  gr.Textbox(type="text", label="Image URL"),
@@ -49,4 +63,4 @@ interface_image_url = gr.Interface(
49
  outputs=outputs_result_json,
50
  title="Text Extraction",
51
  cache_examples=False,
52
- ).queue().launch()
 
 
 
1
  import numpy as np
 
 
2
  import json
3
  import gradio as gr
4
+ import easyocr
5
+
6
+ reader = easyocr.Reader(['en'])
7
 
8
  # ocr = PaddleOCR(use_angle_cls=True, lang='en', use_pdserving=False, cls_batch_num=8, det_batch_num=8, rec_batch_num=8)
9
 
10
+ # ocr = PaddleOCR(use_angle_cls=True, lang='en')
11
 
12
+ # def index(url):
13
+ # response = requests.get(url)
14
+ # img = Image.open(BytesIO(response.content))
15
+ # resize_factor = 1
16
+ # new_size = tuple(int(dim * resize_factor) for dim in img.size)
17
+ # img = img.resize(new_size, Image.Resampling.LANCZOS)
18
 
19
+ # img_array = np.array(img.convert('RGB'))
20
 
21
+ # result = ocr.ocr(img_array)
22
 
23
+ # boxes = [line[0] for line in result]
24
+ # txts = [line[1][0] for line in result]
25
+ # scores = [line[1][1] for line in result]
26
 
27
+ # print(boxes)
28
+ # print(txts)
29
 
30
+ # output_dict = {"texts": txts, "boxes": boxes, "scores": scores}
31
+ # output_json = json.dumps(output_dict) # Convert to JSON string
32
 
33
+ # return output_json
34
+
35
+
36
+ def index(image_url):
37
+ result = reader.readtext(image_url)
38
 
39
+ texts = []
40
+ probs = []
41
+
42
+ for (bbox, text, prob) in result:
43
+ # print(f'Text: {text}, Probability: {prob}')
44
+ texts.append(text)
45
+ probs.append(prob)
46
+
47
+ output_dict = {"texts": texts, "boxes": probs}
48
+ output_json = json.dumps(output_dict)
49
+
50
+ return output_json
51
 
52
  inputs_image_url = [
53
  gr.Textbox(type="text", label="Image URL"),
 
63
  outputs=outputs_result_json,
64
  title="Text Extraction",
65
  cache_examples=False,
66
+ ).queue().launch()
g-ocr.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import cv2
2
+ # import pytesseract
3
+ # import numpy as np
4
+
5
+ # image = cv2.imread('rzse0mcqxbgs8z2pf6lr.png')
6
+
7
+ # def get_grayscale(image):
8
+ # return cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
9
+
10
+ # def remove_noise(image):
11
+ # return cv2.medianBlur(image,5)
12
+
13
+ # def thresholding(image):
14
+ # return cv2.threshold(image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
15
+
16
+ # def dilate(image):
17
+ # kernel = np.ones((5,5),np.uint8)
18
+ # return cv2.dilate(image, kernel, iterations = 1)
19
+
20
+ # def erode(image):
21
+ # kernel = np.ones((5,5),np.uint8)
22
+ # return cv2.erode(image, kernel, iterations = 1)
23
+
24
+ # def opening(image):
25
+ # kernel = np.ones((5,5),np.uint8)
26
+ # return cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel)
27
+
28
+ # def canny(image):
29
+ # return cv2.Canny(image, 100, 200)
30
+
31
+ # def deskew(image):
32
+ # coords = np.column_stack(np.where(image > 0))
33
+ # angle = cv2.minAreaRect(coords)[-1]
34
+ # if angle < -45:
35
+ # angle = -(90 + angle)
36
+ # else:
37
+ # angle = -angle
38
+ # (h, w) = image.shape[:2]
39
+ # center = (w // 2, h // 2)
40
+ # M = cv2.getRotationMatrix2D(center, angle, 1.0)
41
+ # rotated = cv2.warpAffine(image, M, (w, h), flags=cv2.INTER_CUBIC, borderMode=cv2.BORDER_REPLICATE)
42
+ # return rotated
43
+
44
+ # def match_template(image, template):
45
+ # return cv2.matchTemplate(image, template, cv2.TM_CCOEFF_NORMED)
46
+
47
+ # custom_config = r'--oem 3 --psm 6'
48
+ # pytesseract.image_to_string(image, config=custom_config)
49
+
50
+ # gray = get_grayscale(image)
51
+ # thresh = thresholding(gray)
52
+ # opening = opening(gray)
53
+ # canny = canny(gray)
54
+
55
+ import easyocr
56
+
57
+ image_url = 'https://res.cloudinary.com/ddvajyjou/image/upload/v1706960876/rzse0mcqxbgs8z2pf6lr.png'
58
+
59
+ reader = easyocr.Reader(['en'])
60
+ result = reader.readtext(image_url)
61
+
62
+ for (bbox, text, prob) in result:
63
+ print(f'Text: {text}, Probability: {prob}')
requirements.txt CHANGED
@@ -6,4 +6,8 @@ Shapely
6
  requests
7
  numpy
8
  pillow
9
- gradio
 
 
 
 
 
6
  requests
7
  numpy
8
  pillow
9
+ gradio
10
+ torch
11
+ torchvision
12
+ torchaudio
13
+ easyocr
rzse0mcqxbgs8z2pf6lr.png ADDED
tesseract-ocr-w64-setup-5.3.3.20231005.exe ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:79af1f9153b8ff988baffaa164fc70799950078f887e2c93dc3fa7efed674b21
3
+ size 50159184