llmat commited on
Commit
c50bb95
·
verified ·
1 Parent(s): f767869

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import pytesseract
4
+ from PIL import Image
5
+
6
+ def ocr(image):
7
+ # Step 1: Convert the image to gray scale
8
+ gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
9
+
10
+ # Step 2: Perform OCR on the image
11
+ text = pytesseract.image_to_string(gray)
12
+
13
+ # Step 3: Prepare the output
14
+ output = {
15
+ "step1": "The first step is to convert the image to grayscale. This often improves the accuracy of OCR.",
16
+ "step1_image": gray,
17
+ "step2": "The second step is to perform OCR on the grayscale image using pytesseract.",
18
+ "step2_text": text
19
+ }
20
+
21
+ return output
22
+
23
+ iface = gr.Interface(fn=ocr,
24
+ inputs=gr.inputs.Image(type="pil"),
25
+ outputs=["text", "image", "text", "text"])
26
+
27
+ iface.launch()