Commit ·
7cca175
1
Parent(s): 49a46c9
Condition add for images
Browse files
ui.py
CHANGED
|
@@ -1,11 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from api import check_id, check_credit, check_mrz
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
+ [["images/mrz_barcode/demo1.png"], ["images/mrz_barcode/demo2.png"]]
|
| 8 |
-
)
|
| 9 |
|
| 10 |
|
| 11 |
def _format_result_html(result: dict) -> str:
|
|
@@ -90,16 +88,42 @@ def create_interface():
|
|
| 90 |
image_input = gr.Image(label="Upload Image")
|
| 91 |
submit_btn = gr.Button("Read Document", variant="primary", size="lg")
|
| 92 |
|
| 93 |
-
|
| 94 |
-
examples=
|
| 95 |
inputs=image_input,
|
| 96 |
-
label="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
)
|
| 98 |
|
| 99 |
with gr.Column(scale=1, min_width=400):
|
| 100 |
result_html = gr.HTML(label="Extracted Data")
|
| 101 |
raw_json = gr.JSON(label="Raw Response")
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
submit_btn.click(
|
| 104 |
fn=process_image,
|
| 105 |
inputs=[image_input, doc_type],
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from api import check_id, check_credit, check_mrz
|
| 3 |
|
| 4 |
+
ID_EXAMPLES = [[f"images/id/{i}.jpg"] for i in range(1, 8)]
|
| 5 |
+
CREDIT_EXAMPLES = [["images/bank/demo1.jpg"], ["images/bank/demo2.png"], ["images/bank/demo3.png"]]
|
| 6 |
+
MRZ_EXAMPLES = [["images/mrz_barcode/demo1.png"], ["images/mrz_barcode/demo2.png"]]
|
|
|
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
def _format_result_html(result: dict) -> str:
|
|
|
|
| 88 |
image_input = gr.Image(label="Upload Image")
|
| 89 |
submit_btn = gr.Button("Read Document", variant="primary", size="lg")
|
| 90 |
|
| 91 |
+
id_examples = gr.Examples(
|
| 92 |
+
examples=ID_EXAMPLES,
|
| 93 |
inputs=image_input,
|
| 94 |
+
label="ID Card Examples",
|
| 95 |
+
visible=True,
|
| 96 |
+
)
|
| 97 |
+
credit_examples = gr.Examples(
|
| 98 |
+
examples=CREDIT_EXAMPLES,
|
| 99 |
+
inputs=image_input,
|
| 100 |
+
label="Credit Card Examples",
|
| 101 |
+
visible=False,
|
| 102 |
+
)
|
| 103 |
+
mrz_examples = gr.Examples(
|
| 104 |
+
examples=MRZ_EXAMPLES,
|
| 105 |
+
inputs=image_input,
|
| 106 |
+
label="MRZ / Barcode Examples",
|
| 107 |
+
visible=False,
|
| 108 |
)
|
| 109 |
|
| 110 |
with gr.Column(scale=1, min_width=400):
|
| 111 |
result_html = gr.HTML(label="Extracted Data")
|
| 112 |
raw_json = gr.JSON(label="Raw Response")
|
| 113 |
|
| 114 |
+
def on_type_change(choice):
|
| 115 |
+
return (
|
| 116 |
+
gr.update(visible=choice == "ID"),
|
| 117 |
+
gr.update(visible=choice == "Credit Card"),
|
| 118 |
+
gr.update(visible=choice == "MRZ"),
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
doc_type.change(
|
| 122 |
+
fn=on_type_change,
|
| 123 |
+
inputs=doc_type,
|
| 124 |
+
outputs=[id_examples, credit_examples, mrz_examples],
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
submit_btn.click(
|
| 128 |
fn=process_image,
|
| 129 |
inputs=[image_input, doc_type],
|