Spaces:
Sleeping
Sleeping
Commit ·
c2510e6
1
Parent(s): 4314fa9
secc
Browse files- app_blocks.py +2 -7
app_blocks.py
CHANGED
|
@@ -3,7 +3,6 @@ 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']
|
|
@@ -11,17 +10,15 @@ def tesseract_ocr(filepath: str, languages: List[str] = None):
|
|
| 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", ["
|
| 25 |
]
|
| 26 |
|
| 27 |
with gr.Blocks(title=title) as demo:
|
|
@@ -31,7 +28,7 @@ with gr.Blocks(title=title) as demo:
|
|
| 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():
|
|
@@ -44,7 +41,6 @@ with gr.Blocks(title=title) as demo:
|
|
| 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],
|
|
@@ -54,6 +50,5 @@ with gr.Blocks(title=title) as demo:
|
|
| 54 |
|
| 55 |
gr.Markdown(article)
|
| 56 |
|
| 57 |
-
# ✅ Required for Spaces
|
| 58 |
if __name__ == '__main__':
|
| 59 |
demo.queue().launch()
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import gradio as gr
|
| 5 |
|
|
|
|
| 6 |
def tesseract_ocr(filepath: str, languages: List[str] = None):
|
| 7 |
if not languages:
|
| 8 |
languages = ['eng']
|
|
|
|
| 10 |
lang_param = '+'.join(languages)
|
| 11 |
return pytesseract.image_to_string(image=image, lang=lang_param)
|
| 12 |
|
|
|
|
| 13 |
title = "Tesseract OCR"
|
| 14 |
description = "Gradio demo for Tesseract. 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/weird_unicode_math_symbols.png", []],
|
| 19 |
["examples/eurotext.png", ["eng"]],
|
| 20 |
["examples/tesseract_sample.png", ["jpn", "eng"]],
|
| 21 |
+
["examples/chi.jpg", ["chi_sim", "chi_tra"]],
|
| 22 |
]
|
| 23 |
|
| 24 |
with gr.Blocks(title=title) as demo:
|
|
|
|
| 28 |
with gr.Row():
|
| 29 |
with gr.Column():
|
| 30 |
image = gr.Image(type="filepath", label="Input")
|
| 31 |
+
language_choices = pytesseract.get_languages(config='') # <- safer
|
| 32 |
with gr.Accordion("Languages", open=False):
|
| 33 |
languages = gr.CheckboxGroup(language_choices, value=["eng"], label="Language(s)")
|
| 34 |
with gr.Row():
|
|
|
|
| 41 |
btn_submit.click(tesseract_ocr, inputs=[image, languages], outputs=text)
|
| 42 |
btn_clear.add(text)
|
| 43 |
|
|
|
|
| 44 |
gr.Examples(
|
| 45 |
examples=examples,
|
| 46 |
inputs=[image, languages],
|
|
|
|
| 50 |
|
| 51 |
gr.Markdown(article)
|
| 52 |
|
|
|
|
| 53 |
if __name__ == '__main__':
|
| 54 |
demo.queue().launch()
|