Spaces:
Running
Running
Aumkeshchy2003
commited on
Create app_block.py
Browse files- app_block.py +34 -0
app_block.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
with gr.Blocks(title=title) as demo:
|
13 |
+
gr.Markdown(f'<h1 style="text-align: center; margin-bottom: 1rem;">{title}</h1>')
|
14 |
+
gr.Markdown(description)
|
15 |
+
with gr.Row():
|
16 |
+
with gr.Column():
|
17 |
+
image = gr.Image(type="filepath", label="Input")
|
18 |
+
language_choices = pytesseract.get_languages()
|
19 |
+
with gr.Accordion("Languages", open=False):
|
20 |
+
languages = gr.CheckboxGroup(language_choices, type="value", value=["eng"], label='language')
|
21 |
+
with gr.Row():
|
22 |
+
btn_clear = gr.ClearButton([image, languages])
|
23 |
+
btn_submit = gr.Button(value="Submit", variant="primary")
|
24 |
+
with gr.Column():
|
25 |
+
text = gr.Textbox(label="Output")
|
26 |
+
|
27 |
+
btn_submit.click(tesseract_ocr, inputs=[image, languages], outputs=text, api_name="tesseract-ocr")
|
28 |
+
btn_clear.add(text)
|
29 |
+
|
30 |
+
|
31 |
+
gr.Markdown(article)
|
32 |
+
|
33 |
+
if __name__ == '__main__':
|
34 |
+
demo.launch()
|