Danieldu
commited on
Commit
·
e3c89f9
1
Parent(s):
23283c0
upddate example images
Browse files- app.py +27 -2
- example_images/1658.jpg +0 -0
- example_images/16831.jpg +0 -0
- example_images/16870.jpg +0 -0
- example_images/4811.jpg +0 -0
app.py
CHANGED
@@ -4,6 +4,15 @@ from ppocr.utils.visual import draw_ser_results
|
|
4 |
from PIL import Image
|
5 |
import gradio as gr
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
def inference__ppocr(img_path):
|
9 |
|
@@ -31,7 +40,6 @@ def inference__ppocr(img_path):
|
|
31 |
|
32 |
|
33 |
def inference__ppstructure(img_path):
|
34 |
-
|
35 |
ppsutructure = PPStructure(
|
36 |
rec_char_dict_path='zhtw_common_dict.txt',
|
37 |
use_gpu=False,
|
@@ -50,10 +58,17 @@ def inference__ppstructure(img_path):
|
|
50 |
result = [''.join(f"{element['pred']}:{element['transcription']}") for element in result if element['pred']!='O']
|
51 |
return image, "\n".join(result)
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
with gr.Blocks() as demo:
|
54 |
gr.Markdown("<p style='text-align: center; font-size: 50px; font-weight: bold;'>Form Understanding Project - Certificate of Diagnosis</p>")
|
55 |
gr.Markdown("Support languages: Traditional Chinese 🇹🇼")
|
56 |
-
gr.Markdown("version
|
57 |
gr.Markdown("""
|
58 |
## Usage Description
|
59 |
This interface is designed to process and extract information from Certificates of Diagnosis.
|
@@ -62,16 +77,26 @@ with gr.Blocks() as demo:
|
|
62 |
3. Click 'Process' to extract information from the uploaded certificate.
|
63 |
4. The processed image and extracted text will be displayed on the right.
|
64 |
""")
|
|
|
65 |
with gr.Row():
|
66 |
with gr.Column():
|
67 |
gr.Markdown("#### Input Image")
|
68 |
image_input = gr.Image(type='filepath', label='Upload Image')
|
|
|
|
|
|
|
69 |
submit_btn = gr.Button("Process")
|
70 |
with gr.Column():
|
71 |
gr.Markdown("#### Processed Image")
|
72 |
image_output = gr.Image(type="pil", label="Processed Image")
|
73 |
gr.Markdown("#### Extracted Text")
|
74 |
text_output = gr.Textbox(label="Extracted Text")
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
submit_btn.click(
|
77 |
inference__ppstructure,
|
|
|
4 |
from PIL import Image
|
5 |
import gradio as gr
|
6 |
|
7 |
+
example_dir = './example_images'
|
8 |
+
|
9 |
+
example_images = [file for file in os.listdir(example_dir) if file.endswith(('.png', '.jpg', '.jpeg'))]
|
10 |
+
|
11 |
+
def load_image(filename):
|
12 |
+
# Construct full file path
|
13 |
+
file_path = os.path.join(example_dir, filename)
|
14 |
+
# Load and return the image
|
15 |
+
return Image.open(file_path)
|
16 |
|
17 |
def inference__ppocr(img_path):
|
18 |
|
|
|
40 |
|
41 |
|
42 |
def inference__ppstructure(img_path):
|
|
|
43 |
ppsutructure = PPStructure(
|
44 |
rec_char_dict_path='zhtw_common_dict.txt',
|
45 |
use_gpu=False,
|
|
|
58 |
result = [''.join(f"{element['pred']}:{element['transcription']}") for element in result if element['pred']!='O']
|
59 |
return image, "\n".join(result)
|
60 |
|
61 |
+
def update_image_input(filename):
|
62 |
+
# Construct full file path
|
63 |
+
file_path = os.path.join(example_dir, filename)
|
64 |
+
# Return the file path
|
65 |
+
return file_path
|
66 |
+
|
67 |
+
|
68 |
with gr.Blocks() as demo:
|
69 |
gr.Markdown("<p style='text-align: center; font-size: 50px; font-weight: bold;'>Form Understanding Project - Certificate of Diagnosis</p>")
|
70 |
gr.Markdown("Support languages: Traditional Chinese 🇹🇼")
|
71 |
+
gr.Markdown("version:0.1")
|
72 |
gr.Markdown("""
|
73 |
## Usage Description
|
74 |
This interface is designed to process and extract information from Certificates of Diagnosis.
|
|
|
77 |
3. Click 'Process' to extract information from the uploaded certificate.
|
78 |
4. The processed image and extracted text will be displayed on the right.
|
79 |
""")
|
80 |
+
|
81 |
with gr.Row():
|
82 |
with gr.Column():
|
83 |
gr.Markdown("#### Input Image")
|
84 |
image_input = gr.Image(type='filepath', label='Upload Image')
|
85 |
+
# example_dropdown = gr.Dropdown(label="Choose an example", choices=example_images)
|
86 |
+
image_selection = gr.Radio(label="Select an Example Image", choices=example_images)
|
87 |
+
|
88 |
submit_btn = gr.Button("Process")
|
89 |
with gr.Column():
|
90 |
gr.Markdown("#### Processed Image")
|
91 |
image_output = gr.Image(type="pil", label="Processed Image")
|
92 |
gr.Markdown("#### Extracted Text")
|
93 |
text_output = gr.Textbox(label="Extracted Text")
|
94 |
+
|
95 |
+
image_selection.change(
|
96 |
+
update_image_input,
|
97 |
+
inputs=[image_selection],
|
98 |
+
outputs=[image_input]
|
99 |
+
)
|
100 |
|
101 |
submit_btn.click(
|
102 |
inference__ppstructure,
|
example_images/1658.jpg
ADDED
![]() |
example_images/16831.jpg
ADDED
![]() |
example_images/16870.jpg
ADDED
![]() |
example_images/4811.jpg
ADDED
![]() |