File size: 771 Bytes
3668b1a
36723e9
304666d
3668b1a
 
 
 
a6fe218
304666d
a6fe218
9516285
3668b1a
a6fe218
3668b1a
 
 
 
9516285
 
 
 
 
 
 
3668b1a
 
 
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
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()