File size: 1,043 Bytes
d4f2791
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import pytesseract
from PIL import Image
from paddleocr import PaddleOCR

# Initialize PaddleOCR
ocr = PaddleOCR(use_angle_cls=True, lang='en')

def extract_text(image_path):
    # Open the image file
    image = Image.open(image_path).convert('L')

    # Extract text using Tesseract OCR
    tesseract_text = pytesseract.image_to_string(image)

    # Extract text using PaddleOCR
    paddle_results = ocr.ocr(image_path, cls=True)
    paddle_text = "\n".join([line[1][0] for result in paddle_results for line in result])

    # Return extracted text from both OCR engines
    return f"๐Ÿ“ **Tesseract OCR Output:**\n{tesseract_text}\n\n๐Ÿ” **PaddleOCR Output:**\n{paddle_text}"

# Create Gradio Interface
demo = gr.Interface(
    fn=extract_text,
    inputs=gr.Image(type="filepath"),
    outputs="text",
    title="AI-Powered Image Text Extractor",
    description="Upload an image containing text, and the AI will extract and display the text using both Tesseract and PaddleOCR.",
)

# Launch Gradio App
demo.launch()