eoeooe commited on
Commit
add98ca
·
verified ·
1 Parent(s): 69259ad

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import pytesseract
4
+ import numpy as np
5
+ from PIL import Image
6
+
7
+ # ฟังก์ชัน OCR
8
+ def ocr_image(image):
9
+ # แปลงจาก PIL → OpenCV
10
+ img = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
11
+
12
+ # config ภาษาไทย
13
+ custom_config = r'-l tha --oem 3 --psm 6 -c language_model_ngram_space_delimited_language=1'
14
+
15
+ # OCR
16
+ text = pytesseract.image_to_string(img, config=custom_config)
17
+ return text.strip()
18
+
19
+ # Gradio UI
20
+ demo = gr.Interface(
21
+ fn=ocr_image,
22
+ inputs=gr.Image(type="pil", label="อัปโหลดรูปภาพ"),
23
+ outputs=gr.Textbox(label="ข้อความที่ OCR ได้"),
24
+ title="OCR ภาษาไทย (Tesseract)",
25
+ description="อัปโหลดภาพแล้วระบบจะอ่านข้อความภาษาไทยออกมาโดยใช้ Tesseract OCR"
26
+ )
27
+
28
+ if __name__ == "__main__":
29
+ demo.launch()