eoeooe commited on
Commit
0b64d6e
·
verified ·
1 Parent(s): f86558c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -26
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 models ครั้งเดียว (ไม่ต้องสร้างใหม่ทุก inference)
7
- ocr_models = {
8
- 'ch': PaddleOCR(use_angle_cls=True, lang='ch', use_gpu=False),
9
- }
10
 
11
  # ฟังก์ชัน inference
12
- def inference(img, lang):
13
- ocr = ocr_models.get(lang, ocr_models['en']) # default เป็นงกฤษ
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 Fast Demo'
20
- description = 'Upload an image and choose language to extract text using PaddleOCR (supports 80+ languages).'
21
- article = "<p style='text-align: center'><a href='https://github.com/PaddlePaddle/PaddleOCR'>PaddleOCR Github Repo</a></p>"
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
- article=article,
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)