File size: 778 Bytes
c50bb95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import cv2
import pytesseract
from PIL import Image

def ocr(image):
    # Step 1: Convert the image to gray scale
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

    # Step 2: Perform OCR on the image
    text = pytesseract.image_to_string(gray)

    # Step 3: Prepare the output
    output = {
        "step1": "The first step is to convert the image to grayscale. This often improves the accuracy of OCR.",
        "step1_image": gray,
        "step2": "The second step is to perform OCR on the grayscale image using pytesseract.",
        "step2_text": text
    }

    return output

iface = gr.Interface(fn=ocr,
                     inputs=gr.inputs.Image(type="pil"),
                     outputs=["text", "image", "text", "text"])

iface.launch()