Spaces:
Runtime error
Runtime error
Commit
•
da2ea29
0
Parent(s):
Duplicate from awacke1/Image-to-Multilingual-OCR
Browse filesCo-authored-by: Aaron C Wacker <awacke1@users.noreply.huggingface.co>
- .gitattributes +28 -0
- README.md +14 -0
- app.py +64 -0
- backupapp.py +64 -0
- requirements.txt +5 -0
.gitattributes
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
20 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: 🖼️ Image-to-Multilingual-OCR 👁️ Gradio
|
3 |
+
emoji: 🖼️OCR👁️
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: purple
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 2.9.1
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: mit
|
11 |
+
duplicated_from: awacke1/Image-to-Multilingual-OCR
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
|
app.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import PIL
|
3 |
+
from PIL import Image
|
4 |
+
from PIL import ImageDraw
|
5 |
+
import gradio as gr
|
6 |
+
import torch
|
7 |
+
import easyocr
|
8 |
+
|
9 |
+
#torch.hub.download_url_to_file('https://github.com/AaronCWacker/Yggdrasil/blob/main/images/BeautyIsTruthTruthisBeauty.JPG', 'BeautyIsTruthTruthisBeauty.JPG')
|
10 |
+
#torch.hub.download_url_to_file('https://github.com/AaronCWacker/Yggdrasil/blob/main/images/PleaseRepeatLouder.jpg', 'PleaseRepeatLouder.jpg')
|
11 |
+
#torch.hub.download_url_to_file('https://github.com/AaronCWacker/Yggdrasil/blob/main/images/ProhibitedInWhiteHouse.JPG', 'ProhibitedInWhiteHouse.JPG')
|
12 |
+
|
13 |
+
torch.hub.download_url_to_file('https://raw.githubusercontent.com/AaronCWacker/Yggdrasil/master/images/20-Books.jpg','20-Books.jpg')
|
14 |
+
torch.hub.download_url_to_file('https://github.com/JaidedAI/EasyOCR/raw/master/examples/english.png', 'COVID.png')
|
15 |
+
torch.hub.download_url_to_file('https://github.com/JaidedAI/EasyOCR/raw/master/examples/chinese.jpg', 'chinese.jpg')
|
16 |
+
torch.hub.download_url_to_file('https://github.com/JaidedAI/EasyOCR/raw/master/examples/japanese.jpg', 'japanese.jpg')
|
17 |
+
torch.hub.download_url_to_file('https://i.imgur.com/mwQFd7G.jpeg', 'Hindi.jpeg')
|
18 |
+
|
19 |
+
def draw_boxes(image, bounds, color='yellow', width=2):
|
20 |
+
draw = ImageDraw.Draw(image)
|
21 |
+
for bound in bounds:
|
22 |
+
p0, p1, p2, p3 = bound[0]
|
23 |
+
draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
|
24 |
+
return image
|
25 |
+
|
26 |
+
def inference(img, lang):
|
27 |
+
reader = easyocr.Reader(lang)
|
28 |
+
bounds = reader.readtext(img.name)
|
29 |
+
im = PIL.Image.open(img.name)
|
30 |
+
draw_boxes(im, bounds)
|
31 |
+
im.save('result.jpg')
|
32 |
+
return ['result.jpg', pd.DataFrame(bounds).iloc[: , 1:]]
|
33 |
+
|
34 |
+
title = '🖼️Image to Multilingual OCR👁️Gradio'
|
35 |
+
description = 'Multilingual OCR which works conveniently on all devices in multiple languages.'
|
36 |
+
article = "<p style='text-align: center'></p>"
|
37 |
+
|
38 |
+
examples = [
|
39 |
+
#['PleaseRepeatLouder.jpg',['ja']],['ProhibitedInWhiteHouse.JPG',['en']],['BeautyIsTruthTruthisBeauty.JPG',['en']],
|
40 |
+
['20-Books.jpg',['en']],['COVID.png',['en']],['chinese.jpg',['ch_sim', 'en']],['japanese.jpg',['ja', 'en']],['Hindi.jpeg',['hi', 'en']]
|
41 |
+
]
|
42 |
+
|
43 |
+
css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;}"
|
44 |
+
choices = [
|
45 |
+
"ch_sim",
|
46 |
+
"ch_tra",
|
47 |
+
"de",
|
48 |
+
"en",
|
49 |
+
"es",
|
50 |
+
"ja",
|
51 |
+
"hi",
|
52 |
+
"ru"
|
53 |
+
]
|
54 |
+
gr.Interface(
|
55 |
+
inference,
|
56 |
+
[gr.inputs.Image(type='file', label='Input'),gr.inputs.CheckboxGroup(choices, type="value", default=['en'], label='language')],
|
57 |
+
[gr.outputs.Image(type='file', label='Output'), gr.outputs.Dataframe(headers=['text', 'confidence'])],
|
58 |
+
title=title,
|
59 |
+
description=description,
|
60 |
+
article=article,
|
61 |
+
examples=examples,
|
62 |
+
css=css,
|
63 |
+
enable_queue=True
|
64 |
+
).launch(debug=True)
|
backupapp.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import PIL
|
3 |
+
from PIL import Image
|
4 |
+
from PIL import ImageDraw
|
5 |
+
import gradio as gr
|
6 |
+
import torch
|
7 |
+
import easyocr
|
8 |
+
|
9 |
+
#torch.hub.download_url_to_file('https://github.com/AaronCWacker/Yggdrasil/blob/main/images/BeautyIsTruthTruthisBeauty.JPG', 'BeautyIsTruthTruthisBeauty.JPG')
|
10 |
+
#torch.hub.download_url_to_file('https://github.com/AaronCWacker/Yggdrasil/blob/main/images/PleaseRepeatLouder.jpg', 'PleaseRepeatLouder.jpg')
|
11 |
+
#torch.hub.download_url_to_file('https://github.com/AaronCWacker/Yggdrasil/blob/main/images/ProhibitedInWhiteHouse.JPG', 'ProhibitedInWhiteHouse.JPG')
|
12 |
+
|
13 |
+
torch.hub.download_url_to_file('https://raw.githubusercontent.com/AaronCWacker/Yggdrasil/master/images/20-Books.jpg','20-Books.jpg')
|
14 |
+
torch.hub.download_url_to_file('https://github.com/JaidedAI/EasyOCR/raw/master/examples/english.png', 'COVID.png')
|
15 |
+
torch.hub.download_url_to_file('https://github.com/JaidedAI/EasyOCR/raw/master/examples/chinese.jpg', 'chinese.jpg')
|
16 |
+
torch.hub.download_url_to_file('https://github.com/JaidedAI/EasyOCR/raw/master/examples/japanese.jpg', 'japanese.jpg')
|
17 |
+
torch.hub.download_url_to_file('https://i.imgur.com/mwQFd7G.jpeg', 'Hindi.jpeg')
|
18 |
+
|
19 |
+
def draw_boxes(image, bounds, color='yellow', width=2):
|
20 |
+
draw = ImageDraw.Draw(image)
|
21 |
+
for bound in bounds:
|
22 |
+
p0, p1, p2, p3 = bound[0]
|
23 |
+
draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
|
24 |
+
return image
|
25 |
+
|
26 |
+
def inference(img, lang):
|
27 |
+
reader = easyocr.Reader(lang)
|
28 |
+
bounds = reader.readtext(img.name)
|
29 |
+
im = PIL.Image.open(img.name)
|
30 |
+
draw_boxes(im, bounds)
|
31 |
+
im.save('result.jpg')
|
32 |
+
return ['result.jpg', pd.DataFrame(bounds).iloc[: , 1:]]
|
33 |
+
|
34 |
+
title = '🖼️Image to Multilingual OCR👁️Gradio'
|
35 |
+
description = 'Multilingual OCR which works conveniently on all devices in multiple languages.'
|
36 |
+
article = "<p style='text-align: center'></p>"
|
37 |
+
|
38 |
+
examples = [
|
39 |
+
#['PleaseRepeatLouder.jpg',['ja']],['ProhibitedInWhiteHouse.JPG',['en']],['BeautyIsTruthTruthisBeauty.JPG',['en']],
|
40 |
+
['20-Books.jpg',['en']],['COVID.png',['en']],['chinese.jpg',['ch_sim', 'en']],['japanese.jpg',['ja', 'en']],['Hindi.jpeg',['hi', 'en']]
|
41 |
+
]
|
42 |
+
|
43 |
+
css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;}"
|
44 |
+
choices = [
|
45 |
+
"ch_sim",
|
46 |
+
"ch_tra",
|
47 |
+
"de",
|
48 |
+
"en",
|
49 |
+
"es",
|
50 |
+
"ja",
|
51 |
+
"hi",
|
52 |
+
"ru"
|
53 |
+
]
|
54 |
+
gr.Interface(
|
55 |
+
inference,
|
56 |
+
[gr.inputs.Image(type='file', label='Input'),gr.inputs.CheckboxGroup(choices, type="value", default=['en'], label='language')],
|
57 |
+
[gr.outputs.Image(type='file', label='Output'), gr.outputs.Dataframe(headers=['text', 'confidence'])],
|
58 |
+
title=title,
|
59 |
+
description=description,
|
60 |
+
article=article,
|
61 |
+
examples=examples,
|
62 |
+
css=css,
|
63 |
+
enable_queue=True
|
64 |
+
).launch(debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
opencv-python-headless<4.3
|
2 |
+
Pillow
|
3 |
+
gradio
|
4 |
+
torch
|
5 |
+
easyocr
|