Luke
commited on
Commit
·
2d2df69
1
Parent(s):
c5475c8
no message
Browse files
app.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
import os
|
2 |
-
|
3 |
import gradio as gr
|
4 |
import pytesseract
|
5 |
|
@@ -11,7 +10,6 @@ langs = []
|
|
11 |
|
12 |
choices = os.popen('tesseract --list-langs').read().split('\n')[1:-1]
|
13 |
|
14 |
-
|
15 |
# If you don't have tesseract executable in your PATH, include the following:
|
16 |
# pytesseract.pytesseract.tesseract_cmd = r'<full_path_to_your_tesseract_executable>'
|
17 |
# Example tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract'
|
@@ -35,7 +33,6 @@ choices = os.popen('tesseract --list-langs').read().split('\n')[1:-1]
|
|
35 |
# 取得所有語言清單
|
36 |
languages = os.popen('tesseract --list-langs').read().split('\n')[1:-1]
|
37 |
|
38 |
-
|
39 |
print(' ======================================================== ')
|
40 |
# print(' ###### choices:' + choices)
|
41 |
# print(' ###### GET ENV - TESSDATA_PREFIX:' + os.getenv('TESSDATA_PREFIX'))
|
@@ -61,6 +58,9 @@ def preprocess_and_llm(image, validation_type, language):
|
|
61 |
with gr.Blocks() as demo:
|
62 |
with gr.Row():
|
63 |
image_input = gr.Image(type="pil", label="上傳圖片")
|
|
|
|
|
|
|
64 |
validation_type = gr.Dropdown(choices=["身分證正面", "身分證反面"], label="驗證類別")
|
65 |
language_dropdown = gr.Dropdown(choices=languages, value="chi_tra", label="語言")
|
66 |
|
@@ -68,13 +68,13 @@ with gr.Blocks() as demo:
|
|
68 |
ocr_button = gr.Button("使用 OCR")
|
69 |
llm_button = gr.Button("使用 AI LLM")
|
70 |
|
71 |
-
with gr.Row():
|
72 |
-
preprocess_output = gr.Image(label="OCR 預處理圖片")
|
73 |
with gr.Row():
|
74 |
ocr_output = gr.JSON(label="OCR 解析結果")
|
75 |
llm_output = gr.JSON(label="AI LLM 解析結果")
|
76 |
|
77 |
-
ocr_button.click(preprocess_and_ocr, inputs=[image_input, validation_type, language_dropdown],
|
78 |
-
|
|
|
|
|
79 |
|
80 |
demo.launch(share=False)
|
|
|
1 |
import os
|
|
|
2 |
import gradio as gr
|
3 |
import pytesseract
|
4 |
|
|
|
10 |
|
11 |
choices = os.popen('tesseract --list-langs').read().split('\n')[1:-1]
|
12 |
|
|
|
13 |
# If you don't have tesseract executable in your PATH, include the following:
|
14 |
# pytesseract.pytesseract.tesseract_cmd = r'<full_path_to_your_tesseract_executable>'
|
15 |
# Example tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract'
|
|
|
33 |
# 取得所有語言清單
|
34 |
languages = os.popen('tesseract --list-langs').read().split('\n')[1:-1]
|
35 |
|
|
|
36 |
print(' ======================================================== ')
|
37 |
# print(' ###### choices:' + choices)
|
38 |
# print(' ###### GET ENV - TESSDATA_PREFIX:' + os.getenv('TESSDATA_PREFIX'))
|
|
|
58 |
with gr.Blocks() as demo:
|
59 |
with gr.Row():
|
60 |
image_input = gr.Image(type="pil", label="上傳圖片")
|
61 |
+
preprocess_output = gr.Image(type="pil", label="預處理後的圖片")
|
62 |
+
|
63 |
+
with gr.Row():
|
64 |
validation_type = gr.Dropdown(choices=["身分證正面", "身分證反面"], label="驗證類別")
|
65 |
language_dropdown = gr.Dropdown(choices=languages, value="chi_tra", label="語言")
|
66 |
|
|
|
68 |
ocr_button = gr.Button("使用 OCR")
|
69 |
llm_button = gr.Button("使用 AI LLM")
|
70 |
|
|
|
|
|
71 |
with gr.Row():
|
72 |
ocr_output = gr.JSON(label="OCR 解析結果")
|
73 |
llm_output = gr.JSON(label="AI LLM 解析結果")
|
74 |
|
75 |
+
ocr_button.click(preprocess_and_ocr, inputs=[image_input, validation_type, language_dropdown],
|
76 |
+
outputs=[preprocess_output, ocr_output])
|
77 |
+
llm_button.click(preprocess_and_llm, inputs=[image_input, validation_type, language_dropdown],
|
78 |
+
outputs=[preprocess_output, llm_output])
|
79 |
|
80 |
demo.launch(share=False)
|