Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,42 +1,25 @@
|
|
| 1 |
-
import os
|
| 2 |
from paddleocr import PaddleOCR
|
| 3 |
-
from PIL import Image
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
-
# โหลด OCR
|
| 7 |
-
|
| 8 |
-
'ch': PaddleOCR(use_angle_cls=True, lang='ch', use_gpu=False),
|
| 9 |
-
}
|
| 10 |
|
| 11 |
# ฟังก์ชัน inference
|
| 12 |
-
def inference(img
|
| 13 |
-
|
| 14 |
-
result = ocr.ocr(img, cls=True)[0] # cls=True ถ้าต้องการหมุนภาพอัตโนมัติ
|
| 15 |
txts = [line[1][0] for line in result]
|
| 16 |
return '\n'.join(txts)
|
| 17 |
|
| 18 |
# Gradio Interface
|
| 19 |
-
title = 'PaddleOCR
|
| 20 |
-
description = 'Upload an image and
|
| 21 |
-
|
| 22 |
-
examples = [['example.jpg', 'en']] # ต้องมีไฟล์ example.jpg ในโฟลเดอร์เดียวกัน
|
| 23 |
-
css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;}"
|
| 24 |
|
| 25 |
gr.Interface(
|
| 26 |
fn=inference,
|
| 27 |
-
inputs=
|
| 28 |
-
gr.Image(type='filepath', label='Input Image'),
|
| 29 |
-
gr.Dropdown(
|
| 30 |
-
choices=list(ocr_models.keys()),
|
| 31 |
-
value='en',
|
| 32 |
-
type="value",
|
| 33 |
-
label='Language'
|
| 34 |
-
)
|
| 35 |
-
],
|
| 36 |
outputs="text",
|
| 37 |
title=title,
|
| 38 |
description=description,
|
| 39 |
-
|
| 40 |
-
examples=examples,
|
| 41 |
-
css=css
|
| 42 |
).launch(debug=True)
|
|
|
|
|
|
|
| 1 |
from paddleocr import PaddleOCR
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
# โหลด OCR โมเดลภาษา Chinese (Simplified) ครั้งเดียว
|
| 5 |
+
ocr = PaddleOCR(use_angle_cls=True, lang='ch', use_gpu=False)
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# ฟังก์ชัน inference
|
| 8 |
+
def inference(img):
|
| 9 |
+
result = ocr.ocr(img, cls=True)[0] # cls=True ถ้าต้องการหมุนภาพอัตโนมัติ
|
|
|
|
| 10 |
txts = [line[1][0] for line in result]
|
| 11 |
return '\n'.join(txts)
|
| 12 |
|
| 13 |
# Gradio Interface
|
| 14 |
+
title = 'PaddleOCR Chinese Demo'
|
| 15 |
+
description = 'Upload an image and extract Chinese text using PaddleOCR.'
|
| 16 |
+
examples = [['example.jpg']] # ต้องมีไฟล์ example.jpg ในโฟลเดอร์เดียวกัน
|
|
|
|
|
|
|
| 17 |
|
| 18 |
gr.Interface(
|
| 19 |
fn=inference,
|
| 20 |
+
inputs=gr.Image(type='filepath', label='Input Image'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
outputs="text",
|
| 22 |
title=title,
|
| 23 |
description=description,
|
| 24 |
+
examples=examples
|
|
|
|
|
|
|
| 25 |
).launch(debug=True)
|