Delete app.py
Browse files
app.py
DELETED
@@ -1,299 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import requests
|
3 |
-
from PIL import Image
|
4 |
-
|
5 |
-
def check_id(frame):
|
6 |
-
url = "https://api.miniai.live/api/check_id"
|
7 |
-
files = {'image': open(frame, 'rb')}
|
8 |
-
|
9 |
-
r = requests.post(url=url, files=files)
|
10 |
-
|
11 |
-
html = None
|
12 |
-
images = None
|
13 |
-
mrz = None
|
14 |
-
|
15 |
-
status = r.json().get('Status')
|
16 |
-
table_value = ""
|
17 |
-
|
18 |
-
if r.json().get('MRZ') is not None:
|
19 |
-
mrz = r.json().get('MRZ')
|
20 |
-
|
21 |
-
for key, value in r.json().items():
|
22 |
-
if key == 'Status' or key == 'Images' or key == 'MRZ' or key == 'Position':
|
23 |
-
continue
|
24 |
-
|
25 |
-
mrz_value = ''
|
26 |
-
if mrz is not None and mrz.get(key) is not None:
|
27 |
-
mrz_value = mrz[key]
|
28 |
-
del mrz[key]
|
29 |
-
|
30 |
-
row_value = ("<tr>"
|
31 |
-
"<td>{key}</td>"
|
32 |
-
"<td>{value}</td>"
|
33 |
-
"<td>{mrz_value}</td>"
|
34 |
-
"</tr>".format(key=key, value=value, mrz_value=mrz_value))
|
35 |
-
table_value = table_value + row_value
|
36 |
-
|
37 |
-
|
38 |
-
if mrz is not None:
|
39 |
-
for key, value in mrz.items():
|
40 |
-
if key == 'MRZ':
|
41 |
-
value = value.replace('<', '<')
|
42 |
-
value = value.replace(',', '<p>')
|
43 |
-
|
44 |
-
row_value = ("<tr>"
|
45 |
-
"<td>{key}</td>"
|
46 |
-
"<td>{value}</td>"
|
47 |
-
"<td>{mrz_value}</td>"
|
48 |
-
"</tr>".format(key=key, value='', mrz_value=value))
|
49 |
-
table_value = table_value + row_value
|
50 |
-
|
51 |
-
|
52 |
-
html = ("<table>"
|
53 |
-
"<tr>"
|
54 |
-
"<th style=""width:20%"">Field</th>"
|
55 |
-
"<th style=""width:40%"">Value</th>"
|
56 |
-
"<th style=""width:40%"">MRZ</th>"
|
57 |
-
"</tr>"
|
58 |
-
"{table_value}"
|
59 |
-
"</table>".format(table_value=table_value))
|
60 |
-
|
61 |
-
table_value = ""
|
62 |
-
for key, value in r.json().items():
|
63 |
-
if key == 'Images':
|
64 |
-
for details_key, details_value in value.items():
|
65 |
-
for image_key, image_value in details_value.items():
|
66 |
-
if image_key == 'image':
|
67 |
-
row_value = ("<tr>"
|
68 |
-
"<td>{key}</td>"
|
69 |
-
"<td><img src=""data:image/png;base64,{base64_image} width = '200' height= '100' /></td>"
|
70 |
-
"</tr>".format(key=details_key, base64_image=image_value))
|
71 |
-
table_value = table_value + row_value
|
72 |
-
|
73 |
-
images = ("<table>"
|
74 |
-
"<tr>"
|
75 |
-
"<th>Field</th>"
|
76 |
-
"<th>Image</th>"
|
77 |
-
"</tr>"
|
78 |
-
"{table_value}"
|
79 |
-
"</table>".format(table_value=table_value))
|
80 |
-
|
81 |
-
return [html, images]
|
82 |
-
|
83 |
-
|
84 |
-
def check_bank(frame):
|
85 |
-
url = "https://api.miniai.live/api/check_credit"
|
86 |
-
files = {'image': open(frame, 'rb')}
|
87 |
-
|
88 |
-
r = requests.post(url=url, files=files)
|
89 |
-
|
90 |
-
html = None
|
91 |
-
images = None
|
92 |
-
|
93 |
-
status = r.json().get('Status')
|
94 |
-
table_value = ""
|
95 |
-
|
96 |
-
for key, value in r.json().items():
|
97 |
-
if key == 'Status' or key == 'Images' or key == 'Position':
|
98 |
-
continue
|
99 |
-
|
100 |
-
row_value = ("<tr>"
|
101 |
-
"<td>{key}</td>"
|
102 |
-
"<td>{value}</td>"
|
103 |
-
"</tr>".format(key=key, value=value))
|
104 |
-
table_value = table_value + row_value
|
105 |
-
|
106 |
-
html = ("<table>"
|
107 |
-
"<tr>"
|
108 |
-
"<th style=""width:20%"">Field</th>"
|
109 |
-
"<th style=""width:40%"">Value</th>"
|
110 |
-
"</tr>"
|
111 |
-
"{table_value}"
|
112 |
-
"</table>".format(table_value=table_value))
|
113 |
-
|
114 |
-
table_value = ""
|
115 |
-
for key, value in r.json().items():
|
116 |
-
if key == 'Images':
|
117 |
-
for details_key, details_value in value.items():
|
118 |
-
for image_key, image_value in details_value.items():
|
119 |
-
if image_key == 'image':
|
120 |
-
row_value = ("<tr>"
|
121 |
-
"<td>{key}</td>"
|
122 |
-
"<td><img src=""data:image/png;base64,{base64_image} width = '200' height= '100' /></td>"
|
123 |
-
"</tr>".format(key=details_key, base64_image=image_value))
|
124 |
-
table_value = table_value + row_value
|
125 |
-
|
126 |
-
images = ("<table>"
|
127 |
-
"<tr>"
|
128 |
-
"<th>Field</th>"
|
129 |
-
"<th>Image</th>"
|
130 |
-
"</tr>"
|
131 |
-
"{table_value}"
|
132 |
-
"</table>".format(table_value=table_value))
|
133 |
-
|
134 |
-
return [html, images]
|
135 |
-
|
136 |
-
def check_mrz(frame):
|
137 |
-
url = "https://api.miniai.live/api/check_mrz"
|
138 |
-
files = {'image': open(frame, 'rb')}
|
139 |
-
|
140 |
-
r = requests.post(url=url, files=files)
|
141 |
-
|
142 |
-
html = None
|
143 |
-
images = None
|
144 |
-
mrz = None
|
145 |
-
|
146 |
-
status = r.json().get('Status')
|
147 |
-
table_value = ""
|
148 |
-
|
149 |
-
if r.json().get('MRZ') is not None:
|
150 |
-
mrz = r.json().get('MRZ')
|
151 |
-
|
152 |
-
for key, value in r.json().items():
|
153 |
-
if key == 'Status' or key == 'Images' or key == 'MRZ' or key == 'Position':
|
154 |
-
continue
|
155 |
-
|
156 |
-
mrz_value = ''
|
157 |
-
if mrz is not None and mrz.get(key) is not None:
|
158 |
-
mrz_value = mrz[key]
|
159 |
-
del mrz[key]
|
160 |
-
|
161 |
-
row_value = ("<tr>"
|
162 |
-
"<td>{key}</td>"
|
163 |
-
"<td>{mrz_value}</td>"
|
164 |
-
"</tr>".format(key=key, mrz_value=mrz_value))
|
165 |
-
table_value = table_value + row_value
|
166 |
-
|
167 |
-
|
168 |
-
if mrz is not None:
|
169 |
-
for key, value in mrz.items():
|
170 |
-
if key == 'MRZ':
|
171 |
-
value = value.replace('<', '<')
|
172 |
-
value = value.replace(',', '<p>')
|
173 |
-
|
174 |
-
row_value = ("<tr>"
|
175 |
-
"<td>{key}</td>"
|
176 |
-
"<td>{mrz_value}</td>"
|
177 |
-
"</tr>".format(key=key, mrz_value=value))
|
178 |
-
table_value = table_value + row_value
|
179 |
-
|
180 |
-
|
181 |
-
html = ("<table>"
|
182 |
-
"<tr>"
|
183 |
-
"<th style=""width:20%"">Field</th>"
|
184 |
-
"<th style=""width:40%"">MRZ</th>"
|
185 |
-
"</tr>"
|
186 |
-
"{table_value}"
|
187 |
-
"</table>".format(table_value=table_value))
|
188 |
-
|
189 |
-
table_value = ""
|
190 |
-
for key, value in r.json().items():
|
191 |
-
if key == 'Images':
|
192 |
-
for details_key, details_value in value.items():
|
193 |
-
for image_key, image_value in details_value.items():
|
194 |
-
if image_key == 'image':
|
195 |
-
row_value = ("<tr>"
|
196 |
-
"<td>{key}</td>"
|
197 |
-
"<td><img src=""data:image/png;base64,{base64_image} width = '200' height= '100' /></td>"
|
198 |
-
"</tr>".format(key=details_key, base64_image=image_value))
|
199 |
-
table_value = table_value + row_value
|
200 |
-
|
201 |
-
images = ("<table>"
|
202 |
-
"<tr>"
|
203 |
-
"<th>Field</th>"
|
204 |
-
"<th>Image</th>"
|
205 |
-
"</tr>"
|
206 |
-
"{table_value}"
|
207 |
-
"</table>".format(table_value=table_value))
|
208 |
-
|
209 |
-
return [html, images]
|
210 |
-
|
211 |
-
|
212 |
-
# APP Interface
|
213 |
-
with gr.Blocks() as MiniAIdemo:
|
214 |
-
gr.Markdown(
|
215 |
-
"""
|
216 |
-
<a href="https://miniai.live" style="display: flex; align-items: center;">
|
217 |
-
<img src="https://miniai.live/wp-content/uploads/2024/02/logo_name-1-768x426-1.png" style="width: 18%; margin-right: 15px;"/>
|
218 |
-
<div>
|
219 |
-
<p style="font-size: 50px; font-weight: bold; margin-right: 20px;">ID Document Recognition WebAPI Demo</p>
|
220 |
-
</div>
|
221 |
-
</a>
|
222 |
-
<br/>
|
223 |
-
<div style="display: flex; justify-content: center; align-items: center;">
|
224 |
-
<table style="text-align: center;">
|
225 |
-
<tr>
|
226 |
-
<td style="text-align: center; vertical-align: middle;"><a href="https://github.com/MiniAiLive"><img src="https://miniai.live/wp-content/uploads/2024/10/new_git-1-300x67.png" style="height: 50px; margin-right: 5px;" title="GITHUB"/></a></td>
|
227 |
-
<td style="text-align: center; vertical-align: middle;"><a href="https://huggingface.co/MiniAiLive"><img src="https://miniai.live/wp-content/uploads/2024/10/new_hugging-1-300x67.png" style="height: 50px; margin-right: 5px;" title="HuggingFace"/></a></td>
|
228 |
-
<td style="text-align: center; vertical-align: middle;"><a href="https://demo.miniai.live"><img src="https://miniai.live/wp-content/uploads/2024/10/new_gradio-300x67.png" style="height: 50px; margin-right: 5px;" title="Gradio"/></a></td>
|
229 |
-
</tr>
|
230 |
-
<tr>
|
231 |
-
<td style="text-align: center; vertical-align: middle;"><a href="https://docs.miniai.live/"><img src="https://miniai.live/wp-content/uploads/2024/10/a-300x70.png" style="height: 50px; margin-right: 5px;" title="Documentation"/></a></td>
|
232 |
-
<td style="text-align: center; vertical-align: middle;"><a href="https://www.youtube.com/@miniailive"><img src="https://miniai.live/wp-content/uploads/2024/10/Untitled-1-300x70.png" style="height: 50px; margin-right: 5px;" title="Youtube"/></a></td>
|
233 |
-
<td style="text-align: center; vertical-align: middle;"><a href="https://play.google.com/store/apps/dev?id=5831076207730531667"><img src="https://miniai.live/wp-content/uploads/2024/10/googleplay-300x62.png" style="height: 50px; margin-right: 5px;" title="Google Play"/></a></td>
|
234 |
-
</tr>
|
235 |
-
</table>
|
236 |
-
</div>
|
237 |
-
<br/>
|
238 |
-
"""
|
239 |
-
)
|
240 |
-
with gr.Tabs():
|
241 |
-
with gr.Tab("ID Document Recognition"):
|
242 |
-
with gr.Row():
|
243 |
-
with gr.Column(scale=3):
|
244 |
-
im_id_in = gr.Image(type='filepath', height=300)
|
245 |
-
gr.Examples(
|
246 |
-
[
|
247 |
-
"images/id/demo1.jpg",
|
248 |
-
"images/id/demo2.png",
|
249 |
-
"images/id/demo3.png",
|
250 |
-
],
|
251 |
-
inputs=im_id_in
|
252 |
-
)
|
253 |
-
btn_f_id = gr.Button("Check Document Details", variant='primary')
|
254 |
-
with gr.Column(scale=5):
|
255 |
-
table_id_out = gr.HTML()
|
256 |
-
with gr.Column(scale=2):
|
257 |
-
im_id_out = gr.HTML()
|
258 |
-
|
259 |
-
btn_f_id.click(check_id, inputs=im_id_in, outputs=[table_id_out, im_id_out])
|
260 |
-
with gr.Tab("Bank/Credit Recognition"):
|
261 |
-
with gr.Row():
|
262 |
-
with gr.Column(scale=3):
|
263 |
-
im_bank_in = gr.Image(type='filepath', height=300)
|
264 |
-
gr.Examples(
|
265 |
-
[
|
266 |
-
"images/bank/demo1.jpg",
|
267 |
-
"images/bank/demo2.png",
|
268 |
-
"images/bank/demo3.png",
|
269 |
-
],
|
270 |
-
inputs=im_bank_in
|
271 |
-
)
|
272 |
-
btn_f_bank = gr.Button("Check Document Details", variant='primary')
|
273 |
-
with gr.Column(scale=5):
|
274 |
-
table_bank_out = gr.HTML()
|
275 |
-
with gr.Column(scale=2):
|
276 |
-
im_bank_out = gr.HTML()
|
277 |
-
|
278 |
-
btn_f_bank.click(check_bank, inputs=im_bank_in, outputs=[table_bank_out, im_bank_out])
|
279 |
-
with gr.Tab("MRZ/Barcode Recognition"):
|
280 |
-
with gr.Row():
|
281 |
-
with gr.Column(scale=3):
|
282 |
-
im_mrz_in = gr.Image(type='filepath', height=300)
|
283 |
-
gr.Examples(
|
284 |
-
[
|
285 |
-
"images/mrz_barcode/demo1.png",
|
286 |
-
"images/mrz_barcode/demo2.png",
|
287 |
-
],
|
288 |
-
inputs=im_mrz_in
|
289 |
-
)
|
290 |
-
btn_f_mrz = gr.Button("Check Document Details", variant='primary')
|
291 |
-
with gr.Column(scale=5):
|
292 |
-
table_mrz_out = gr.HTML()
|
293 |
-
with gr.Column(scale=2):
|
294 |
-
im_mrz_out = gr.HTML()
|
295 |
-
|
296 |
-
btn_f_mrz.click(check_mrz, inputs=im_mrz_in, outputs=[table_mrz_out, im_mrz_out])
|
297 |
-
gr.HTML('<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FMiniAiLive%2FID-Document-Recognition-Demo"><img src="https://api.visitorbadge.io/api/combined?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FMiniAiLive%2FID-Document-Recognition-Demo&label=VISITORS&labelColor=%2337d67a&countColor=%23ff8a65&style=plastic&labelStyle=none" /></a>')
|
298 |
-
if __name__ == "__main__":
|
299 |
-
MiniAIdemo.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|