File size: 1,687 Bytes
1e36507
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import gradio as gr
from multiocr import OcrEngine
from multiocr.utils import draw_bounding_boxes

# Define a function that takes an input image and processes it
def process_image(input_image, ocr_type):
    # Perform y`our internal processing here
    # Example: Convert the image to grayscale
    ocr = OcrEngine(ocr_type)
    data = ocr.text_extraction(input_image)
    json_response = ocr.text_extraction_to_df(data)
    output_image = draw_bounding_boxes(input_image, data)

    return output_image, json_response

# Define the Gradio interface
def app():
    ocr_type = gr.inputs.Dropdown(choices=["tesseract", "paddle_ocr", "easy_ocr", "aws_textract"], label="selct one ocr")
    # Create an input component for uploading the image
    image_input = gr.inputs.Image(label="Upload Image", type="filepath")

    # Create an output component for displaying the processed image
    image_output = gr.outputs.Image(label="Output Image", type="pil")

    # Create an output component for displaying the JSON response
    df = gr.outputs.Dataframe(label="DataFrame", type="pandas")

    # Create a function that will be called when the app is run
    def process_and_display_image(input_image, ocr_type):
        processed_image, json_response = process_image(input_image, ocr_type)
        return processed_image, json_response

    # Create the Gradio interface
    examples = [["./data/simple.jpg"], ["./data/invoice.jpg"], ["./data/publay_sample.jpeg"]]
    gr.Interface(fn=process_and_display_image, inputs=[image_input, ocr_type], outputs=[image_output, df], examples=examples).launch(server_port=7860,server_name="0.0.0.0")

if __name__ == "__main__":
    # Run the app
    app()