Spaces:
Sleeping
Sleeping
Update app_blocks.py
Browse files- app_blocks.py +4 -3
app_blocks.py
CHANGED
@@ -5,10 +5,10 @@ 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, config='--psm 7')
|
11 |
-
return pytesseract.image_to_string(image=image, lang=', '.join(languages))
|
12 |
|
13 |
title = "Tesseract OCR"
|
14 |
description = "Gradio demo for Tesseract. Tesseract is an open source text recognition (OCR) Engine."
|
@@ -29,13 +29,14 @@ with gr.Blocks(title=title) as demo:
|
|
29 |
language_choices = pytesseract.get_languages()
|
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(
|
|
|
5 |
|
6 |
import gradio as gr
|
7 |
|
8 |
+
def tesseract_ocr(filepath: str, languages: List[str]=None, psm: int = 7):
|
9 |
image = Image.open(filepath)
|
10 |
# return pytesseract.image_to_string(image=image, lang=', '.join(languages) if languages else None, config='--psm 7')
|
11 |
+
return pytesseract.image_to_string(image=image, lang=', '.join(languages) if languages else None, config='--psm' + psm)
|
12 |
|
13 |
title = "Tesseract OCR"
|
14 |
description = "Gradio demo for Tesseract. Tesseract is an open source text recognition (OCR) Engine."
|
|
|
29 |
language_choices = pytesseract.get_languages()
|
30 |
with gr.Accordion("Languages", open=False):
|
31 |
languages = gr.CheckboxGroup(language_choices, type="value", value=["eng"], label='language')
|
32 |
+
psm_slider = gr.Slider(minimum=0, maximum=13, step=1, value=7, label="PSM level")
|
33 |
with gr.Row():
|
34 |
btn_clear = gr.ClearButton([image, languages])
|
35 |
btn_submit = gr.Button(value="Submit", variant="primary")
|
36 |
with gr.Column():
|
37 |
text = gr.Textbox(label="Output")
|
38 |
|
39 |
+
btn_submit.click(tesseract_ocr, inputs=[image, languages, psm_slider], outputs=text, api_name="tesseract-ocr")
|
40 |
btn_clear.add(text)
|
41 |
|
42 |
gr.Examples(
|