Spaces:
Running
Running
File size: 1,056 Bytes
4f90a60 e3e0609 4f90a60 30adacb 4f90a60 e3e0609 4f90a60 e3e0609 dde57c5 4f90a60 48db9f7 4f90a60 e3e0609 4f90a60 e3e0609 4f90a60 48db9f7 e3e0609 4f90a60 48db9f7 |
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 35 36 37 38 39 40 41 |
import gradio as gr
import pytesseract
from PIL import Image
import easyocr
##
easyocr_reader = easyocr.Reader(['en', 'pt', 'es'], gpu=False) #
#Tesseract
def tesseract_ocr(image):
return pytesseract.image_to_string(image)
#EasyOCR
def easyocr_ocr(image):
return ' '.join(easyocr_reader.readtext(image, detail=0))
#
def extract_text_from_image(ocr_engine, image):
if ocr_engine == "Tesseract":
return tesseract_ocr(image)
elif ocr_engine == "EasyOCR":
return easyocr_ocr(image)
else:
return "Invalid OCR selection."
#Gradio
iface = gr.Interface(
fn=extract_text_from_image,
inputs=[gr.Dropdown(["Tesseract", "EasyOCR"], label="Select the OCR Engine"), "image"],
outputs="text",
title="OCR Img2txt",
description="This application uses Optical Character Recognition (OCR) technology to extract text from images. Choose between Tesseract OCR and EasyOCR engine to process images containing printed text, converting it into editable and searchable text."
)
iface.launch(debug=True)
|