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()