image2text / app.py
Heecheol's picture
refactor: pass original image as numpy array to EasyOCR
a6fe218
Raw History Blame Contribute Delete
771 Bytes
import cv2
import numpy as np
import easyocr
import gradio as gr
from PIL import Image
def ocr_image_to_text(image: Image.Image):
image_np = np.array(image)
reader = easyocr.Reader(['en', 'ko'])
text = ' '.join([item[1] for item in reader.readtext(image_np)])
return text
# Gradio μΈν„°νŽ˜μ΄μŠ€λ₯Ό μ •μ˜ν•©λ‹ˆλ‹€.
image_input = gr.inputs.Image(label="Upload an image")
text_output = gr.outputs.Textbox(label="Extracted Text")
# μž…λ ₯ 예제λ₯Ό μ •μ˜ν•©λ‹ˆλ‹€.
example_image = 'example.jpg'
examples = [
[example_image]
]
iface = gr.Interface(fn=ocr_image_to_text, inputs=image_input, outputs=text_output, title="OCR Image to Text", examples=examples)
# μΈν„°νŽ˜μ΄μŠ€λ₯Ό μ‹€ν–‰ν•˜κ³  Hugging Face Spaces에 λ°°ν¬ν•©λ‹ˆλ‹€.
iface.launch()