Spaces:
Sleeping
Sleeping
Commit ·
4314fa9
1
Parent(s): 6d136a9
sec
Browse files- README.md +5 -7
- app_blocks.py +59 -0
- app_interface.py +38 -0
- gitattributes +35 -0
- packages.txt +1 -0
- requirements.txt +2 -0
README.md
CHANGED
|
@@ -1,14 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: blue
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
app_file:
|
| 9 |
pinned: false
|
| 10 |
-
license: apache-2.0
|
| 11 |
-
short_description: extract text from images
|
| 12 |
---
|
| 13 |
|
| 14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Tesseract OCR
|
| 3 |
+
emoji: 🐢
|
| 4 |
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.36.0
|
| 8 |
+
app_file: app_blocks.py
|
| 9 |
pinned: false
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app_blocks.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import List
|
| 2 |
+
import pytesseract
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
# OCR function
|
| 7 |
+
def tesseract_ocr(filepath: str, languages: List[str] = None):
|
| 8 |
+
if not languages:
|
| 9 |
+
languages = ['eng']
|
| 10 |
+
image = Image.open(filepath)
|
| 11 |
+
lang_param = '+'.join(languages)
|
| 12 |
+
return pytesseract.image_to_string(image=image, lang=lang_param)
|
| 13 |
+
|
| 14 |
+
# Metadata
|
| 15 |
+
title = "Tesseract OCR"
|
| 16 |
+
description = "Gradio demo for Tesseract. Tesseract is an open source text recognition (OCR) Engine."
|
| 17 |
+
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>"
|
| 18 |
+
|
| 19 |
+
# Local examples
|
| 20 |
+
examples = [
|
| 21 |
+
["examples/weird_unicode_math_symbols.png", []],
|
| 22 |
+
["examples/eurotext.png", ["eng"]],
|
| 23 |
+
["examples/tesseract_sample.png", ["jpn", "eng"]],
|
| 24 |
+
["examples/chi.jpg", ["HanS", "HanT"]],
|
| 25 |
+
]
|
| 26 |
+
|
| 27 |
+
with gr.Blocks(title=title) as demo:
|
| 28 |
+
gr.Markdown(f'<h1 style="text-align: center; margin-bottom: 1rem;">{title}</h1>')
|
| 29 |
+
gr.Markdown(description)
|
| 30 |
+
|
| 31 |
+
with gr.Row():
|
| 32 |
+
with gr.Column():
|
| 33 |
+
image = gr.Image(type="filepath", label="Input")
|
| 34 |
+
language_choices = pytesseract.get_languages()
|
| 35 |
+
with gr.Accordion("Languages", open=False):
|
| 36 |
+
languages = gr.CheckboxGroup(language_choices, value=["eng"], label="Language(s)")
|
| 37 |
+
with gr.Row():
|
| 38 |
+
btn_clear = gr.ClearButton([image, languages])
|
| 39 |
+
btn_submit = gr.Button(value="Submit", variant="primary")
|
| 40 |
+
|
| 41 |
+
with gr.Column():
|
| 42 |
+
text = gr.Textbox(label="Output")
|
| 43 |
+
|
| 44 |
+
btn_submit.click(tesseract_ocr, inputs=[image, languages], outputs=text)
|
| 45 |
+
btn_clear.add(text)
|
| 46 |
+
|
| 47 |
+
# ✅ Function bound directly here
|
| 48 |
+
gr.Examples(
|
| 49 |
+
examples=examples,
|
| 50 |
+
inputs=[image, languages],
|
| 51 |
+
outputs=[text],
|
| 52 |
+
fn=tesseract_ocr
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
gr.Markdown(article)
|
| 56 |
+
|
| 57 |
+
# ✅ Required for Spaces
|
| 58 |
+
if __name__ == '__main__':
|
| 59 |
+
demo.queue().launch()
|
app_interface.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
return pytesseract.image_to_string(image=image, lang=', '.join(languages))
|
| 11 |
+
|
| 12 |
+
title = "Tesseract OCR"
|
| 13 |
+
description = "Gradio demo for Tesseract. Tesseract is an open source text recognition (OCR) Engine."
|
| 14 |
+
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>"
|
| 15 |
+
examples = [
|
| 16 |
+
['examples/eurotext.png', ['eng']],
|
| 17 |
+
['examples/tesseract_sample.png', ['jpn', 'eng']],
|
| 18 |
+
['examples/chi.jpg', ['HanS', 'HanT']]
|
| 19 |
+
]
|
| 20 |
+
|
| 21 |
+
language_choices = pytesseract.get_languages()
|
| 22 |
+
|
| 23 |
+
demo = gr.Interface(
|
| 24 |
+
fn=tesseract_ocr,
|
| 25 |
+
inputs=[
|
| 26 |
+
gr.Image(type="filepath", label="Input"),
|
| 27 |
+
gr.CheckboxGroup(language_choices, type="value", value=['eng'], label='language')
|
| 28 |
+
],
|
| 29 |
+
outputs='text',
|
| 30 |
+
title=title,
|
| 31 |
+
description=description,
|
| 32 |
+
article=article,
|
| 33 |
+
examples=examples,
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
if __name__ == '__main__':
|
| 37 |
+
demo.launch()
|
| 38 |
+
print("Finished running")
|
gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
packages.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
tesseract-ocr-all
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
pytesseract
|