OCR_Tutorial / app.py
llmat's picture
Create app.py
c50bb95 verified
raw
history blame
778 Bytes
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()