Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.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(share=True)
|
| 38 |
+
print("Finished running")
|