Spaces:
Running
Running
Commit
·
a53fc8c
0
Parent(s):
Initial: initial commit
Browse files- .gitattributes +37 -0
- .gitignore +1 -0
- README.md +14 -0
- app_blocks.py +49 -0
- app_interface.py +41 -0
- examples/example1.png +0 -0
- examples/example2.png +0 -0
- examples/example3.png +0 -0
- examples/example4.png +0 -0
- packages.txt +1 -0
- requirements.txt +2 -0
- tessdata/eng.traineddata +3 -0
- tessdata/shn.traineddata +3 -0
.gitattributes
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt 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 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
tessdata/shn.traineddata filter=lfs diff=lfs merge=lfs -text
|
37 |
+
tessdata/eng.traineddata filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.DS_Store
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Shan Tesseract OCR
|
3 |
+
emoji: 🦀
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: yellow
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 5.22.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: mit
|
11 |
+
short_description: Demo for Shan-Tesseract-OCR
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app_blocks.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import List
|
2 |
+
|
3 |
+
import pytesseract
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
import gradio as gr
|
7 |
+
|
8 |
+
def tesseract_ocr(filepath: str, languages: List[str]):
|
9 |
+
image = Image.open(filepath)
|
10 |
+
oem_psm_config = '--oem 3 --psm 11 --tessdata-dir ./tessdata'
|
11 |
+
return pytesseract.image_to_string(image=image, lang='+'.join(languages) if languages else None, config=oem_psm_config)
|
12 |
+
|
13 |
+
title = "Shan Tesseract OCR"
|
14 |
+
description = "Gradio demo for Tesseract-OCR Shan. Tesseract is an open source text recognition (OCR) Engine."
|
15 |
+
article = "<p style='text-align: center'><a href='https://tesseract-ocr.github.io/' target='_blank'>Tesseract documentation</a> | <a href='https://github.com/tesseract-ocr/tesseract' target='_blank'>Github Repo</a></p>"
|
16 |
+
examples = [
|
17 |
+
["examples/example2.png", ["eng", "shn"]],
|
18 |
+
["examples/example3.png", ["eng", "shn"]],
|
19 |
+
["examples/example4.png", ["eng", "shn"]],
|
20 |
+
["examples/example1.png", ["eng", "shn"]],
|
21 |
+
]
|
22 |
+
|
23 |
+
with gr.Blocks(title=title) as demo:
|
24 |
+
gr.Markdown(f'<h1 style="text-align: center; margin-bottom: 1rem;">{title}</h1>')
|
25 |
+
gr.Markdown(description)
|
26 |
+
with gr.Row():
|
27 |
+
with gr.Column():
|
28 |
+
image = gr.Image(type="filepath", label="Input")
|
29 |
+
language_choices = pytesseract.get_languages(config='--tessdata-dir ./tessdata') # get available languages from tessdata prefix
|
30 |
+
with gr.Accordion("Languages", open=False):
|
31 |
+
languages = gr.CheckboxGroup(language_choices, type="value", value=["eng"], label='language')
|
32 |
+
with gr.Row():
|
33 |
+
btn_clear = gr.ClearButton([image, languages])
|
34 |
+
btn_submit = gr.Button(value="Submit", variant="primary")
|
35 |
+
with gr.Column():
|
36 |
+
text = gr.Textbox(label="Output")
|
37 |
+
|
38 |
+
btn_submit.click(tesseract_ocr, inputs=[image, languages], outputs=text, api_name="tesseract-ocr")
|
39 |
+
btn_clear.add(text)
|
40 |
+
|
41 |
+
gr.Examples(
|
42 |
+
examples=examples,
|
43 |
+
inputs=[image, languages],
|
44 |
+
)
|
45 |
+
|
46 |
+
gr.Markdown(article)
|
47 |
+
|
48 |
+
if __name__ == '__main__':
|
49 |
+
demo.launch()
|
app_interface.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import List
|
2 |
+
|
3 |
+
import pytesseract
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
import gradio as gr
|
7 |
+
|
8 |
+
def tesseract_ocr(filepath: str, languages: List[str]):
|
9 |
+
image = Image.open(filepath)
|
10 |
+
oem_psm_config = '--oem 3 --psm 11 --tessdata-dir ./tessdata'
|
11 |
+
return pytesseract.image_to_string(image=image, lang='+'.join(languages), config=oem_psm_config)
|
12 |
+
|
13 |
+
title = "Shan Tesseract OCR"
|
14 |
+
description = "Gradio demo for Tesseract-OCR Shan. Tesseract is an open source text recognition (OCR) Engine."
|
15 |
+
article = "<p style='text-align: center'><a href='https://tesseract-ocr.github.io/' target='_blank'>Tesseract documentation</a> | <a href='https://github.com/tesseract-ocr/tesseract' target='_blank'>Github Repo</a></p>"
|
16 |
+
|
17 |
+
examples = [
|
18 |
+
["examples/example2.png", ["eng", "shn"]],
|
19 |
+
["examples/example3.png", ["eng", "shn"]],
|
20 |
+
["examples/example4.png", ["eng", "shn"]],
|
21 |
+
["examples/example1.png", ["eng", "shn"]],
|
22 |
+
]
|
23 |
+
|
24 |
+
language_choices = pytesseract.get_languages(config='--tessdata-dir ./tessdata')
|
25 |
+
|
26 |
+
demo = gr.Interface(
|
27 |
+
fn=tesseract_ocr,
|
28 |
+
inputs=[
|
29 |
+
gr.Image(type="filepath", label="Input"),
|
30 |
+
gr.CheckboxGroup(language_choices, type="value", value=['eng'], label='language')
|
31 |
+
],
|
32 |
+
outputs='text',
|
33 |
+
title=title,
|
34 |
+
description=description,
|
35 |
+
article=article,
|
36 |
+
examples=examples,
|
37 |
+
)
|
38 |
+
|
39 |
+
if __name__ == '__main__':
|
40 |
+
demo.launch()
|
41 |
+
print("Finished running")
|
examples/example1.png
ADDED
![]() |
examples/example2.png
ADDED
![]() |
examples/example3.png
ADDED
![]() |
examples/example4.png
ADDED
![]() |
packages.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
tesseract-ocr-all
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
pytesseract
|
tessdata/eng.traineddata
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7d4322bd2a7749724879683fc3912cb542f19906c83bcc1a52132556427170b2
|
3 |
+
size 4113088
|
tessdata/shn.traineddata
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:023e21f297d24ad64c062a78788f695ddfff9e3170cfcff5fcc466a39ed500ef
|
3 |
+
size 13375840
|