Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
@@ -3,37 +3,9 @@ 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 = []
|
@@ -46,7 +18,7 @@ def index(image_url):
|
|
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 = [
|
@@ -63,4 +35,4 @@ interface_image_url = gr.Interface(
|
|
63 |
outputs=outputs_result_json,
|
64 |
title="Text Extraction",
|
65 |
cache_examples=False,
|
66 |
-
).queue().launch()
|
|
|
3 |
import gradio as gr
|
4 |
import easyocr
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
def index(image_url):
|
8 |
+
reader = easyocr.Reader(['en'])
|
9 |
result = reader.readtext(image_url)
|
10 |
|
11 |
texts = []
|
|
|
18 |
|
19 |
output_dict = {"texts": texts, "boxes": probs}
|
20 |
output_json = json.dumps(output_dict)
|
21 |
+
|
22 |
return output_json
|
23 |
|
24 |
inputs_image_url = [
|
|
|
35 |
outputs=outputs_result_json,
|
36 |
title="Text Extraction",
|
37 |
cache_examples=False,
|
38 |
+
).queue().launch()
|
g-ocr.py
CHANGED
@@ -52,6 +52,36 @@
|
|
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'
|
|
|
52 |
# opening = opening(gray)
|
53 |
# canny = canny(gray)
|
54 |
|
55 |
+
|
56 |
+
# ocr = PaddleOCR(use_angle_cls=True, lang='en', use_pdserving=False, cls_batch_num=8, det_batch_num=8, rec_batch_num=8)
|
57 |
+
|
58 |
+
# ocr = PaddleOCR(use_angle_cls=True, lang='en')
|
59 |
+
|
60 |
+
# def index(url):
|
61 |
+
# response = requests.get(url)
|
62 |
+
# img = Image.open(BytesIO(response.content))
|
63 |
+
# resize_factor = 1
|
64 |
+
# new_size = tuple(int(dim * resize_factor) for dim in img.size)
|
65 |
+
# img = img.resize(new_size, Image.Resampling.LANCZOS)
|
66 |
+
|
67 |
+
# img_array = np.array(img.convert('RGB'))
|
68 |
+
|
69 |
+
# result = ocr.ocr(img_array)
|
70 |
+
|
71 |
+
# boxes = [line[0] for line in result]
|
72 |
+
# txts = [line[1][0] for line in result]
|
73 |
+
# scores = [line[1][1] for line in result]
|
74 |
+
|
75 |
+
# print(boxes)
|
76 |
+
# print(txts)
|
77 |
+
|
78 |
+
# output_dict = {"texts": txts, "boxes": boxes, "scores": scores}
|
79 |
+
# output_json = json.dumps(output_dict) # Convert to JSON string
|
80 |
+
|
81 |
+
# return output_json
|
82 |
+
|
83 |
+
|
84 |
+
|
85 |
import easyocr
|
86 |
|
87 |
image_url = 'https://res.cloudinary.com/ddvajyjou/image/upload/v1706960876/rzse0mcqxbgs8z2pf6lr.png'
|