AyoAgbaje commited on
Commit
4a575fb
·
verified ·
1 Parent(s): 04a35fa

Upload 7 files

Browse files
Files changed (7) hide show
  1. __init__.py +0 -0
  2. app.py +76 -0
  3. no_img.jpg +0 -0
  4. records.csv +17 -0
  5. report.docx +0 -0
  6. requirements.txt +8 -0
  7. script.ipynb +489 -0
__init__.py ADDED
File without changes
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pandas as pd
3
+ import os
4
+ import matplotlib.pyplot as plt
5
+ from matplotlib import image
6
+
7
+ import deepface
8
+ from deepface import DeepFace
9
+ import gradio as gr
10
+ from fns.utility_fns import empty_img, make_records
11
+
12
+ def image_predict(mat_no_, student_name, img_):
13
+ mat_no_ = mat_no_.upper()
14
+ models = ['VGG-Face', 'Facenet', 'Facenet512', 'openFace', 'DeepFace', 'DeepId', 'ArcFace', 'Dlib', 'SFace']
15
+ backends = ['opencv', 'ssd', 'dlib', 'mtcnn', 'retinaface', 'mediapipe']
16
+ # df = pd.read_csv("records.csv")
17
+ df = make_records()
18
+ mat_nos = [i for i in df["matric number"].values]
19
+
20
+ if mat_no_ in mat_nos:
21
+ verified = True
22
+ else:
23
+ verified = False
24
+
25
+ if verified:
26
+ df_sort = df[df["matric number"] == mat_no_]
27
+ imgs_ = df_sort["img paths"].values[0]
28
+ imgs = imgs_.split(" ")
29
+ h_start = round(0.05*img_.shape[0])
30
+ h_end = round(0.95*img_.shape[0])
31
+ w_start = round(0.05*img_.shape[1])
32
+ w_end = round(0.95*img_.shape[1])
33
+ img_ = img_[h_start:h_end, w_start:w_end]
34
+ verify_status = list()
35
+ for img in imgs:
36
+ result = DeepFace.verify(
37
+ img1_path = img_,
38
+ img2_path = img,
39
+ model_name = models[1],
40
+ distance_metric = 'cosine',
41
+ enforce_detection = False,
42
+ detector_backend = backends[0],
43
+ align = False,
44
+ threshold = .2
45
+ )
46
+ verify_status.append(result["verified"])
47
+
48
+ if True in verify_status:
49
+ response_ = f"{student_name} is verified and can proceed to vote"
50
+ img_match_id = imgs.index(True)
51
+ img_match = imgs[img_match_id]
52
+ img_match = image.imread(img_match)
53
+
54
+ # return response_, img_match
55
+ else:
56
+ response_ = f"{student_name} cannot verified as image does not match image in the Database"
57
+ img_match = empty_img()
58
+ # return response_, img_match
59
+ else:
60
+ response_ = f"Matric number of the student:{student_name} is not found in Database"
61
+ img_match = empty_img()
62
+
63
+ return response_, img_match
64
+
65
+
66
+
67
+ with gr.Blocks() as demo:
68
+ m_no = gr.Textbox(placeholder = "Input Matric Number in the format (DEPT/YY/NNNN) here:", label = "MATRIC NO")
69
+ name_ = gr.Textbox(placeholder = "Input your name here", label = "Student Name".upper())
70
+ image_ = gr.Image(label = 'Input Image to be verified', source = "webcam")
71
+ output1 = gr.Textbox(label = 'Verification Response')
72
+ output2 = gr.Image(type = "filepath", label = "Database Image match")
73
+ btn = gr.Button('Verify')
74
+ btn.click(fn = image_predict, inputs = [m_no, name_, image_], outputs = [output1, output2])
75
+
76
+ demo.launch(share = True)
no_img.jpg ADDED
records.csv ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ matric number,img paths
2
+ CSC/19/0463,records/CSC-19-0463/photo_2024-08-02_07-38-10.jpg records/CSC-19-0463/photo_2024-08-02_07-38-19.jpg records/CSC-19-0463/photo_2024-08-02_07-38-26.jpg records/CSC-19-0463/photo_2024-08-02_07-38-32.jpg records/CSC-19-0463/photo_2024-08-02_07-38-36.jpg
3
+ CYS/18/5874,records/CYS-18-5874/1721676589154.jpg records/CYS-18-5874/1721676589194.jpg
4
+ CYS/18/5879,records/CYS-18-5879/1721675647292.jpg records/CYS-18-5879/1721675647368.jpg
5
+ CYS/18/5882,records/CYS-18-5882/1721675648611.jpg records/CYS-18-5882/1721675648649.jpg
6
+ CYS/18/5883,records/CYS-18-5883/1721676589269.jpg
7
+ CYS/18/5884,records/CYS-18-5884/1721675648162.jpg
8
+ CYS/18/5885,records/CYS-18-5885/1721675646760.jpg records/CYS-18-5885/1721675646862.jpg
9
+ CYS/18/5893,records/CYS-18-5893/1721675646947.jpg records/CYS-18-5893/1721675647055.jpg
10
+ CYS/18/5894,records/CYS-18-5894/1721675648229.jpg records/CYS-18-5894/1721675648364.jpg
11
+ CYS/18/5898,records/CYS-18-5898/1721676589232.jpg
12
+ CYS/18/5901,records/CYS-18-5901/1721675646243.jpg records/CYS-18-5901/1721675646342.jpg
13
+ CYS/18/8472,records/CYS-18-8472/1721675648545.jpg
14
+ CYS/18/8473,records/CYS-18-8473/1721675647715.jpg records/CYS-18-8473/1721675647976.jpg
15
+ CYS/18/8477,records/CYS-18-8477/1721675647442.jpg records/CYS-18-8477/1721675647564.jpg
16
+ CYS/18/8479,records/CYS-18-8479/1721675646498.jpg
17
+ CYS/18/8484,records/CYS-18-8484/1721675647162.jpg
report.docx ADDED
Binary file (21.2 kB). View file
 
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ tensorflow==2.15.0
2
+ opencv-python
3
+ gradio
4
+ matplotlib
5
+ deepface
6
+ numpy
7
+ pandas
8
+ tqdm
script.ipynb ADDED
@@ -0,0 +1,489 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [
8
+ {
9
+ "name": "stdout",
10
+ "output_type": "stream",
11
+ "text": [
12
+ "WARNING:tensorflow:From c:\\Users\\Ayo Agbaje\\my_venv_\\lib\\site-packages\\tf_keras\\src\\losses.py:2976: The name tf.losses.sparse_softmax_cross_entropy is deprecated. Please use tf.compat.v1.losses.sparse_softmax_cross_entropy instead.\n",
13
+ "\n"
14
+ ]
15
+ }
16
+ ],
17
+ "source": [
18
+ "import numpy as np\n",
19
+ "import pandas as pd\n",
20
+ "import os\n",
21
+ "import shutil\n",
22
+ "import tqdm\n",
23
+ "from tqdm.auto import trange, tqdm\n",
24
+ "import matplotlib.pyplot as plt\n",
25
+ "from matplotlib import image\n",
26
+ "\n",
27
+ "import deepface\n",
28
+ "from deepface import DeepFace\n",
29
+ "import gradio as gr"
30
+ ]
31
+ },
32
+ {
33
+ "cell_type": "code",
34
+ "execution_count": 84,
35
+ "metadata": {},
36
+ "outputs": [],
37
+ "source": [
38
+ "models = ['VGG-Face', 'Facenet', 'Facenet512', 'openFace', 'DeepFace', 'DeepId', 'ArcFace', 'Dlib', 'SFace']\n",
39
+ "backends = ['opencv', 'ssd', 'dlib', 'mtcnn', 'retinaface', 'mediapipe']\n",
40
+ "\n",
41
+ "result = DeepFace.verify(\n",
42
+ " img1_path = 'records/CYS-18-5884/1721675648162.jpg',\n",
43
+ " img2_path = 'records/CYS-18-8479/1721675646498.jpg',\n",
44
+ " model_name = models[1],\n",
45
+ " distance_metric = 'cosine',\n",
46
+ " enforce_detection = False,\n",
47
+ " detector_backend = backends[0],\n",
48
+ " align = False,\n",
49
+ " threshold = .2\n",
50
+ ")"
51
+ ]
52
+ },
53
+ {
54
+ "cell_type": "code",
55
+ "execution_count": 85,
56
+ "metadata": {},
57
+ "outputs": [
58
+ {
59
+ "data": {
60
+ "text/plain": [
61
+ "{'verified': False,\n",
62
+ " 'distance': 0.8278660258791868,\n",
63
+ " 'threshold': 0.2,\n",
64
+ " 'model': 'Facenet',\n",
65
+ " 'detector_backend': 'opencv',\n",
66
+ " 'similarity_metric': 'cosine',\n",
67
+ " 'facial_areas': {'img1': {'x': 0,\n",
68
+ " 'y': 0,\n",
69
+ " 'w': 1459,\n",
70
+ " 'h': 2210,\n",
71
+ " 'left_eye': None,\n",
72
+ " 'right_eye': None},\n",
73
+ " 'img2': {'x': 0,\n",
74
+ " 'y': 0,\n",
75
+ " 'w': 1664,\n",
76
+ " 'h': 2639,\n",
77
+ " 'left_eye': None,\n",
78
+ " 'right_eye': None}},\n",
79
+ " 'time': 8.36}"
80
+ ]
81
+ },
82
+ "execution_count": 85,
83
+ "metadata": {},
84
+ "output_type": "execute_result"
85
+ }
86
+ ],
87
+ "source": [
88
+ "result"
89
+ ]
90
+ },
91
+ {
92
+ "cell_type": "code",
93
+ "execution_count": 186,
94
+ "metadata": {},
95
+ "outputs": [
96
+ {
97
+ "data": {
98
+ "application/vnd.jupyter.widget-view+json": {
99
+ "model_id": "d13346d4bce04924a03b289d7ff4cd44",
100
+ "version_major": 2,
101
+ "version_minor": 0
102
+ },
103
+ "text/plain": [
104
+ " 0%| | 0/15 [00:00<?, ?it/s]"
105
+ ]
106
+ },
107
+ "metadata": {},
108
+ "output_type": "display_data"
109
+ },
110
+ {
111
+ "data": {
112
+ "application/vnd.jupyter.widget-view+json": {
113
+ "model_id": "c1b56cc2eaf447d4b6290aef07cae2cf",
114
+ "version_major": 2,
115
+ "version_minor": 0
116
+ },
117
+ "text/plain": [
118
+ " 0%| | 0/15 [00:00<?, ?it/s]"
119
+ ]
120
+ },
121
+ "metadata": {},
122
+ "output_type": "display_data"
123
+ }
124
+ ],
125
+ "source": [
126
+ "mat_no = list()\n",
127
+ "for i in tqdm(os.listdir(\"records\")):\n",
128
+ " mat_no.append(\"/\".join(i.split(\"-\")))\n",
129
+ "\n",
130
+ "\n",
131
+ "img_path = list()\n",
132
+ "for i in tqdm(os.listdir(\"records\")):\n",
133
+ " record_ = f\"records/{i}\"\n",
134
+ " rec_ = list()\n",
135
+ " for n, j in enumerate((os.listdir(record_))):\n",
136
+ " rec_.append(f\"records/{i}/{j}\")\n",
137
+ " img_path.append(\" \".join(rec_)) "
138
+ ]
139
+ },
140
+ {
141
+ "cell_type": "code",
142
+ "execution_count": 187,
143
+ "metadata": {},
144
+ "outputs": [
145
+ {
146
+ "data": {
147
+ "text/plain": [
148
+ "(15, 15)"
149
+ ]
150
+ },
151
+ "execution_count": 187,
152
+ "metadata": {},
153
+ "output_type": "execute_result"
154
+ }
155
+ ],
156
+ "source": [
157
+ "len(img_path), len(mat_no)"
158
+ ]
159
+ },
160
+ {
161
+ "cell_type": "code",
162
+ "execution_count": 188,
163
+ "metadata": {},
164
+ "outputs": [],
165
+ "source": [
166
+ "records_df = pd.DataFrame(\n",
167
+ " data = {\n",
168
+ " \"matric number\": mat_no,\n",
169
+ " \"img paths\": img_path\n",
170
+ " }\n",
171
+ ")\n",
172
+ "records_df.head()\n",
173
+ "records_df.to_csv(\"records.csv\", index=0)"
174
+ ]
175
+ },
176
+ {
177
+ "cell_type": "code",
178
+ "execution_count": 189,
179
+ "metadata": {},
180
+ "outputs": [
181
+ {
182
+ "name": "stdout",
183
+ "output_type": "stream",
184
+ "text": [
185
+ "Matric number found in Database\n"
186
+ ]
187
+ }
188
+ ],
189
+ "source": [
190
+ "# simple python workflow\n",
191
+ "\n",
192
+ "mat_no_ = input(\"Input Matric No here(DEPT/YY/NNNN).....\")\n",
193
+ "student_name = input(\"Input your name here.......\")\n",
194
+ "\n",
195
+ "df = pd.read_csv(\"records.csv\")\n",
196
+ "mat_nos = [i for i in df[\"matric number\"].values]\n",
197
+ "\n",
198
+ "if mat_no_ in mat_nos:\n",
199
+ " print(\"Matric number found in Database\")\n",
200
+ " verified = True\n",
201
+ "else:\n",
202
+ " print(\"Student matric number not found in database\")\n",
203
+ " verified = False"
204
+ ]
205
+ },
206
+ {
207
+ "cell_type": "code",
208
+ "execution_count": 190,
209
+ "metadata": {},
210
+ "outputs": [],
211
+ "source": [
212
+ "if verified:\n",
213
+ " df_sort = df[df[\"matric number\"] == mat_no_]"
214
+ ]
215
+ },
216
+ {
217
+ "cell_type": "code",
218
+ "execution_count": 191,
219
+ "metadata": {},
220
+ "outputs": [
221
+ {
222
+ "data": {
223
+ "text/html": [
224
+ "<div>\n",
225
+ "<style scoped>\n",
226
+ " .dataframe tbody tr th:only-of-type {\n",
227
+ " vertical-align: middle;\n",
228
+ " }\n",
229
+ "\n",
230
+ " .dataframe tbody tr th {\n",
231
+ " vertical-align: top;\n",
232
+ " }\n",
233
+ "\n",
234
+ " .dataframe thead th {\n",
235
+ " text-align: right;\n",
236
+ " }\n",
237
+ "</style>\n",
238
+ "<table border=\"1\" class=\"dataframe\">\n",
239
+ " <thead>\n",
240
+ " <tr style=\"text-align: right;\">\n",
241
+ " <th></th>\n",
242
+ " <th>matric number</th>\n",
243
+ " <th>img paths</th>\n",
244
+ " </tr>\n",
245
+ " </thead>\n",
246
+ " <tbody>\n",
247
+ " <tr>\n",
248
+ " <th>0</th>\n",
249
+ " <td>CYS/18/5874</td>\n",
250
+ " <td>records/CYS-18-5874/1721676589154.jpg records/...</td>\n",
251
+ " </tr>\n",
252
+ " </tbody>\n",
253
+ "</table>\n",
254
+ "</div>"
255
+ ],
256
+ "text/plain": [
257
+ " matric number img paths\n",
258
+ "0 CYS/18/5874 records/CYS-18-5874/1721676589154.jpg records/..."
259
+ ]
260
+ },
261
+ "execution_count": 191,
262
+ "metadata": {},
263
+ "output_type": "execute_result"
264
+ }
265
+ ],
266
+ "source": [
267
+ "df_sort"
268
+ ]
269
+ },
270
+ {
271
+ "cell_type": "code",
272
+ "execution_count": 192,
273
+ "metadata": {},
274
+ "outputs": [
275
+ {
276
+ "data": {
277
+ "text/plain": [
278
+ "['records/CYS-18-5874/1721676589154.jpg',\n",
279
+ " 'records/CYS-18-5874/1721676589194.jpg']"
280
+ ]
281
+ },
282
+ "execution_count": 192,
283
+ "metadata": {},
284
+ "output_type": "execute_result"
285
+ }
286
+ ],
287
+ "source": [
288
+ "imgs_ = df_sort[\"img paths\"].values[0]\n",
289
+ "imgs = imgs_.split(\" \")\n",
290
+ "imgs"
291
+ ]
292
+ },
293
+ {
294
+ "cell_type": "code",
295
+ "execution_count": 197,
296
+ "metadata": {},
297
+ "outputs": [],
298
+ "source": [
299
+ "img_ = image.imread('records/CYS-18-8472/1721675648545.jpg')\n",
300
+ "# img_"
301
+ ]
302
+ },
303
+ {
304
+ "cell_type": "code",
305
+ "execution_count": 198,
306
+ "metadata": {},
307
+ "outputs": [],
308
+ "source": [
309
+ "verify_status = list()\n",
310
+ "for img in imgs:\n",
311
+ " result = DeepFace.verify(\n",
312
+ " img1_path = img_,\n",
313
+ " img2_path = img,\n",
314
+ " model_name = models[1],\n",
315
+ " distance_metric = 'cosine',\n",
316
+ " enforce_detection = False,\n",
317
+ " detector_backend = backends[0],\n",
318
+ " align = False,\n",
319
+ " threshold = .2\n",
320
+ " )\n",
321
+ "\n",
322
+ " verify_status.append(result[\"verified\"])"
323
+ ]
324
+ },
325
+ {
326
+ "cell_type": "code",
327
+ "execution_count": 206,
328
+ "metadata": {},
329
+ "outputs": [
330
+ {
331
+ "data": {
332
+ "text/plain": [
333
+ "0"
334
+ ]
335
+ },
336
+ "execution_count": 206,
337
+ "metadata": {},
338
+ "output_type": "execute_result"
339
+ }
340
+ ],
341
+ "source": [
342
+ "verify_status.index(False)"
343
+ ]
344
+ },
345
+ {
346
+ "cell_type": "code",
347
+ "execution_count": 9,
348
+ "metadata": {},
349
+ "outputs": [
350
+ {
351
+ "name": "stdout",
352
+ "output_type": "stream",
353
+ "text": [
354
+ "Running on local URL: http://127.0.0.1:7866\n",
355
+ "\n",
356
+ "To create a public link, set `share=True` in `launch()`.\n"
357
+ ]
358
+ },
359
+ {
360
+ "data": {
361
+ "text/html": [
362
+ "<div><iframe src=\"http://127.0.0.1:7866/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
363
+ ],
364
+ "text/plain": [
365
+ "<IPython.core.display.HTML object>"
366
+ ]
367
+ },
368
+ "metadata": {},
369
+ "output_type": "display_data"
370
+ },
371
+ {
372
+ "data": {
373
+ "text/plain": []
374
+ },
375
+ "execution_count": 9,
376
+ "metadata": {},
377
+ "output_type": "execute_result"
378
+ },
379
+ {
380
+ "name": "stderr",
381
+ "output_type": "stream",
382
+ "text": [
383
+ "Traceback (most recent call last):\n",
384
+ " File \"c:\\Users\\Ayo Agbaje\\my_venv_\\lib\\site-packages\\gradio\\routes.py\", line 422, in run_predict\n",
385
+ " output = await app.get_blocks().process_api(\n",
386
+ " File \"c:\\Users\\Ayo Agbaje\\my_venv_\\lib\\site-packages\\gradio\\blocks.py\", line 1326, in process_api\n",
387
+ " data = self.postprocess_data(fn_index, result[\"prediction\"], state)\n",
388
+ " File \"c:\\Users\\Ayo Agbaje\\my_venv_\\lib\\site-packages\\gradio\\blocks.py\", line 1260, in postprocess_data\n",
389
+ " prediction_value = block.postprocess(prediction_value)\n",
390
+ " File \"c:\\Users\\Ayo Agbaje\\my_venv_\\lib\\site-packages\\gradio\\components.py\", line 1868, in postprocess\n",
391
+ " raise ValueError(\"Cannot process this value as an Image\")\n",
392
+ "ValueError: Cannot process this value as an Image\n"
393
+ ]
394
+ }
395
+ ],
396
+ "source": [
397
+ "def image_predict(mat_no_, student_name, img_):\n",
398
+ " models = ['VGG-Face', 'Facenet', 'Facenet512', 'openFace', 'DeepFace', 'DeepId', 'ArcFace', 'Dlib', 'SFace']\n",
399
+ " backends = ['opencv', 'ssd', 'dlib', 'mtcnn', 'retinaface', 'mediapipe']\n",
400
+ " df = pd.read_csv(\"records.csv\")\n",
401
+ " mat_nos = [i for i in df[\"matric number\"].values]\n",
402
+ "\n",
403
+ " if mat_no_ in mat_nos:\n",
404
+ " verified = True\n",
405
+ " else:\n",
406
+ " verified = False\n",
407
+ " \n",
408
+ " if verified:\n",
409
+ " df_sort = df[df[\"matric number\"] == mat_no_]\n",
410
+ " imgs_ = df_sort[\"img paths\"].values[0]\n",
411
+ " imgs = imgs_.split(\" \")\n",
412
+ "\n",
413
+ " verify_status = list()\n",
414
+ " for img in imgs:\n",
415
+ " result = DeepFace.verify(\n",
416
+ " img1_path = img_,\n",
417
+ " img2_path = img,\n",
418
+ " model_name = models[1],\n",
419
+ " distance_metric = 'cosine',\n",
420
+ " enforce_detection = False,\n",
421
+ " detector_backend = backends[0],\n",
422
+ " align = False,\n",
423
+ " threshold = .2\n",
424
+ " )\n",
425
+ "\n",
426
+ " verify_status.append(result[\"verified\"])\n",
427
+ "\n",
428
+ " if True in verify_status:\n",
429
+ " response_ = f\"{student_name} verified\"\n",
430
+ " img_match_id = imgs.index(True)\n",
431
+ " img_match = imgs[img_match_id]\n",
432
+ " img_match = gr.Image(value = \"no_img.jpg\")\n",
433
+ "\n",
434
+ " return response_, img_match\n",
435
+ " else:\n",
436
+ " response_ = f\"{student_name} not verified(does not match image in the Database)\"\n",
437
+ " img_match = gr.Image(value = img_)\n",
438
+ " return response_, img_match\n",
439
+ " else:\n",
440
+ " response__ = f\"{student_name} not found in Database\"\n",
441
+ " img_match = gr.Image(value = \"no_img.jpg\")\n",
442
+ " \n",
443
+ " return response__, img_match\n",
444
+ " \n",
445
+ "\n",
446
+ "\n",
447
+ "with gr.Blocks() as demo:\n",
448
+ " m_no = gr.Textbox(label = \"Input Matric No here(DEPT/YY/NNNN).....\")\n",
449
+ " name_ = gr.Textbox(label = \"Input your name here.......\")\n",
450
+ " image_ = gr.Image(label = 'Input Image to be predicted', source = \"webcam\")\n",
451
+ " output1 = gr.Textbox(label = 'Response')\n",
452
+ " output2 = gr.Image()\n",
453
+ " btn = gr.Button('Verify')\n",
454
+ " btn.click(fn = image_predict, inputs = [m_no, name_, image_], outputs = [output1, output2])\n",
455
+ "\n",
456
+ "demo.launch(share = False)"
457
+ ]
458
+ },
459
+ {
460
+ "cell_type": "code",
461
+ "execution_count": null,
462
+ "metadata": {},
463
+ "outputs": [],
464
+ "source": []
465
+ }
466
+ ],
467
+ "metadata": {
468
+ "kernelspec": {
469
+ "display_name": "my_venv_",
470
+ "language": "python",
471
+ "name": "python3"
472
+ },
473
+ "language_info": {
474
+ "codemirror_mode": {
475
+ "name": "ipython",
476
+ "version": 3
477
+ },
478
+ "file_extension": ".py",
479
+ "mimetype": "text/x-python",
480
+ "name": "python",
481
+ "nbconvert_exporter": "python",
482
+ "pygments_lexer": "ipython3",
483
+ "version": "3.10.5"
484
+ },
485
+ "orig_nbformat": 4
486
+ },
487
+ "nbformat": 4,
488
+ "nbformat_minor": 2
489
+ }