Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,14 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import easyocr
|
| 3 |
from PIL import Image
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
reader = easyocr.Reader(['en', 'vi', 'ja', 'ch_sim']) # Thêm ngôn ngữ bạn cần
|
| 7 |
|
| 8 |
def ocr_image(image):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
image = Image.open(image)
|
| 12 |
|
| 13 |
-
# Nhận diện văn bản
|
| 14 |
results = reader.readtext(image)
|
| 15 |
text = "\n".join([res[1] for res in results])
|
| 16 |
return text
|
|
@@ -20,8 +18,8 @@ demo = gr.Interface(
|
|
| 20 |
fn=ocr_image,
|
| 21 |
inputs=gr.Image(type="pil"),
|
| 22 |
outputs="text",
|
| 23 |
-
title="OCR Đa Ngôn Ngữ
|
| 24 |
-
description="Nhận diện chữ trong ảnh
|
| 25 |
)
|
| 26 |
|
| 27 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import easyocr
|
| 3 |
from PIL import Image
|
| 4 |
+
import numpy as np
|
| 5 |
|
| 6 |
+
reader = easyocr.Reader(['en', 'vi', 'ja', 'ch_sim'], gpu=False) # TẮT GPU
|
|
|
|
| 7 |
|
| 8 |
def ocr_image(image):
|
| 9 |
+
if isinstance(image, Image.Image):
|
| 10 |
+
image = np.array(image)
|
|
|
|
| 11 |
|
|
|
|
| 12 |
results = reader.readtext(image)
|
| 13 |
text = "\n".join([res[1] for res in results])
|
| 14 |
return text
|
|
|
|
| 18 |
fn=ocr_image,
|
| 19 |
inputs=gr.Image(type="pil"),
|
| 20 |
outputs="text",
|
| 21 |
+
title="OCR Đa Ngôn Ngữ (Chạy trên CPU)",
|
| 22 |
+
description="Nhận diện chữ trong ảnh - Hỗ trợ Tiếng Anh, Việt, Nhật, Trung"
|
| 23 |
)
|
| 24 |
|
| 25 |
demo.launch()
|