Anjiurine commited on
Commit
8db76a6
1 Parent(s): f0001a0
README.md CHANGED
@@ -1,11 +1,11 @@
1
  ---
2
  title: Tesseract OCR
3
- emoji: 🔥
4
- colorFrom: red
5
- colorTo: blue
6
  sdk: gradio
7
- sdk_version: 4.15.0
8
- app_file: app.py
9
  pinned: false
10
  ---
11
 
 
1
  ---
2
  title: Tesseract OCR
3
+ emoji: 🐢
4
+ colorFrom: blue
5
+ colorTo: purple
6
  sdk: gradio
7
+ sdk_version: 3.40.1
8
+ app_file: app_blocks.py
9
  pinned: false
10
  ---
11
 
app_blocks.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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]=None):
9
+ image = Image.open(filepath)
10
+ return pytesseract.image_to_string(image=image, lang=', '.join(languages) if languages else None)
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/weird_unicode_math_symbols.png", []],
17
+ ["examples/eurotext.png", ["eng"]],
18
+ ["examples/tesseract_sample.png", ["jpn", "eng"]],
19
+ ["examples/chi.jpg", ["HanS", "HanT"]],
20
+ ]
21
+
22
+ with gr.Blocks(title=title) as demo:
23
+ gr.Markdown(f'<h1 style="text-align: center; margin-bottom: 1rem;">{title}</h1>')
24
+ gr.Markdown(description)
25
+ with gr.Row():
26
+ with gr.Column():
27
+ image = gr.Image(type="filepath", label="Input")
28
+ language_choices = pytesseract.get_languages()
29
+ with gr.Accordion("Languages", open=False):
30
+ languages = gr.CheckboxGroup(language_choices, type="value", value=["eng"], label='language')
31
+ with gr.Row():
32
+ btn_clear = gr.ClearButton([image, languages])
33
+ btn_submit = gr.Button(value="Submit", variant="primary")
34
+ with gr.Column():
35
+ text = gr.Textbox(label="Output")
36
+
37
+ btn_submit.click(tesseract_ocr, inputs=[image, languages], outputs=text, api_name="tesseract-ocr")
38
+ btn_clear.add(text)
39
+
40
+ gr.Examples(
41
+ examples=examples,
42
+ inputs=[image, languages],
43
+ )
44
+
45
+ gr.Markdown(article)
46
+
47
+ if __name__ == '__main__':
48
+ demo.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")
examples/F4BB08E1-08B9-448A-ADDD-B017EE3CF617.jpg ADDED
examples/Screenshot_6.png ADDED
examples/chi.jpg ADDED
examples/eurotext.png ADDED
examples/image0.jfif ADDED
Binary file (360 kB). View file
 
examples/tesseract_sample.png ADDED
examples/unknown (1).png ADDED
examples/weird_unicode_math_symbols.png ADDED
packages.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ tesseract-ocr-all
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ pytesseract