aminaB9 commited on
Commit
cd17ace
Β·
1 Parent(s): c707c62

Added image processing

Browse files
Files changed (1) hide show
  1. app.py +11 -12
app.py CHANGED
@@ -184,7 +184,7 @@ def extract_emb(image, modelName=FRMODELS[0], mode=None, imgPath=None):
184
  embs = F.normalize(embs, dim=1)
185
  embs = embs.detach().numpy()
186
  embs = embs.squeeze(0)
187
- if mode != None:
188
  subject = imgPath.split('/')[-2]
189
  os.makedirs(f'./embeddings/{subject}', exist_ok=True)
190
  emb_path = f'./embeddings/{subject}/{mode}-emb.txt'
@@ -227,14 +227,13 @@ with gr.Blocks() as demo:
227
  <p>This demo shows <strong>Suraksh.AI's</strong> biometric search solution under <strong>FHE</strong>.</p>
228
  <ul>
229
  <li><strong>Scenario 1</strong>: Searching an enrolled subject. For this scenario, the reference and probe should be from the same subject. Expected outcome: <span style='color: green; font-weight: bold;'>βœ”οΈ Found</span></li>
230
- <li><strong>Scenario 2</strong>: Searching an enrolled subject with high recognition threshold. For this scenario, the reference and probe should be from the same subject and increase the recognition threshold. Expected outcome: <span style='color: red; font-weight: bold;'>❌ Not Found</span></li>
231
  <li><strong>Scenario 3</strong>: Searching a non-enrolled subject. For this scenario, choose a probe not enrolled. Expected outcome: <span style='color: red; font-weight: bold;'>❌ Not Found</span></li>
232
- <li><strong>Scenario 4</strong>: Searching a non-enrolled subject with low recognition threshold. For this scenario, choose a probe not enrolled and lower the recognition threshold. Expected outcome: <span style='color: green; font-weight: bold;'>βœ”οΈ Found</span></li>
233
  </ul>
234
  """
235
  )
236
-
237
-
238
 
239
  with gr.Row():
240
  gr.Markdown("### Setup Phase: πŸ” Generate the FHE public and secret keys.")
@@ -254,6 +253,7 @@ with gr.Blocks() as demo:
254
  gr.Markdown("## Phase 1: Enrollment")
255
  with gr.Row():
256
  gr.Markdown("### Step 1: Upload or select a reference facial image for enrollment.")
 
257
  with gr.Row():
258
  selectedImagePath = gr.State()
259
  count = gr.State(0)
@@ -277,8 +277,6 @@ with gr.Blocks() as demo:
277
  label="Choose a face recognition model"
278
  )
279
  with gr.Column():
280
- selectedImagePath = gr.State()
281
- refDB_gallery.select(fn=get_selected_image, inputs=None, outputs=[image_input_enroll, selectedImagePath])
282
  key_button = gr.Button("Generate embedding")
283
  enroll_emb_text = gr.JSON(label="Reference embedding")
284
  mode = gr.State("enroll")
@@ -287,7 +285,7 @@ with gr.Blocks() as demo:
287
 
288
 
289
  with gr.Row():
290
- gr.Markdown("""Facial embeddings are **INVERTIBLE** and lead to the **RECONSTRUCTION** of their raw facial images.""")
291
  with gr.Row():
292
  gr.Markdown("### Example:")
293
  with gr.Row():
@@ -299,7 +297,7 @@ with gr.Blocks() as demo:
299
  Reconstructed_image = gr.Image(label="Reconstructed")
300
  btn.click(fn=load_rec_image, outputs=Reconstructed_image)
301
  with gr.Row():
302
- gr.Markdown("""Facial embeddings protection is a must! At **Suraksh.AI**, we protect facial embeddings using FHE.""")
303
 
304
  with gr.Row():
305
  gr.Markdown("### Step 3: πŸ”’ Encrypt reference embedding using FHE.")
@@ -354,18 +352,19 @@ with gr.Blocks() as demo:
354
  image_upload_auth = gr.Image(label="Upload a facial image.", type="pil", sources="upload")
355
  image_upload_auth.change(fn=crop_face_to_112x112, inputs=image_upload_auth, outputs=[image_input_auth,selectedImagePath_auth])
356
  with gr.Column():
 
357
  prob_gallery = gr.Gallery(value=example_images_auth, columns=3)
358
  prob_gallery.select(fn=get_selected_image_auth, inputs=None, outputs=[image_input_auth,selectedImagePath_auth])
359
  with gr.Column():
360
  selectedImage = gr.Image(type="pil", label="Probe facial image", interactive=False)
361
  image_input_auth.change(fn=lambda img: img, inputs=image_input_auth, outputs=selectedImage)
 
 
362
 
363
  with gr.Row():
364
  gr.Markdown("### Step 2: Generate probe facial embedding.")
365
  with gr.Row():
366
- with gr.Column():
367
- selectedImagePath_auth = gr.State()
368
- prob_gallery.select(fn=get_selected_image_auth, inputs=None, outputs=[image_input_auth,selectedImagePath_auth])
369
  key_button = gr.Button("Generate embedding")
370
  prob_emb_text = gr.JSON(label="Probe embedding")
371
  mode = gr.State("auth")
 
184
  embs = F.normalize(embs, dim=1)
185
  embs = embs.detach().numpy()
186
  embs = embs.squeeze(0)
187
+ if mode != None:
188
  subject = imgPath.split('/')[-2]
189
  os.makedirs(f'./embeddings/{subject}', exist_ok=True)
190
  emb_path = f'./embeddings/{subject}/{mode}-emb.txt'
 
227
  <p>This demo shows <strong>Suraksh.AI's</strong> biometric search solution under <strong>FHE</strong>.</p>
228
  <ul>
229
  <li><strong>Scenario 1</strong>: Searching an enrolled subject. For this scenario, the reference and probe should be from the same subject. Expected outcome: <span style='color: green; font-weight: bold;'>βœ”οΈ Found</span></li>
230
+ <li><strong>Scenario 2</strong>: Searching an enrolled subject with high recognition threshold. For this scenario, the reference and probe should be from the same subject and the recognition threshold set to a high value. Expected outcome: <span style='color: red; font-weight: bold;'>❌ Not Found</span></li>
231
  <li><strong>Scenario 3</strong>: Searching a non-enrolled subject. For this scenario, choose a probe not enrolled. Expected outcome: <span style='color: red; font-weight: bold;'>❌ Not Found</span></li>
232
+ <li><strong>Scenario 4</strong>: Searching a non-enrolled subject with low recognition threshold. For this scenario, choose a probe not enrolled and lower the high recognition threshold. Expected outcome: <span style='color: green; font-weight: bold;'>βœ”οΈ Found</span></li>
233
  </ul>
234
  """
235
  )
236
+
 
237
 
238
  with gr.Row():
239
  gr.Markdown("### Setup Phase: πŸ” Generate the FHE public and secret keys.")
 
253
  gr.Markdown("## Phase 1: Enrollment")
254
  with gr.Row():
255
  gr.Markdown("### Step 1: Upload or select a reference facial image for enrollment.")
256
+
257
  with gr.Row():
258
  selectedImagePath = gr.State()
259
  count = gr.State(0)
 
277
  label="Choose a face recognition model"
278
  )
279
  with gr.Column():
 
 
280
  key_button = gr.Button("Generate embedding")
281
  enroll_emb_text = gr.JSON(label="Reference embedding")
282
  mode = gr.State("enroll")
 
285
 
286
 
287
  with gr.Row():
288
+ gr.Markdown("""Facial embeddings are <span style='color:red; font-weight:bold'>INVERTIBLE</span> and lead to the <span style='color:red; font-weight:bold'>RECONSTRUCTION</span> of their raw facial images.""")
289
  with gr.Row():
290
  gr.Markdown("### Example:")
291
  with gr.Row():
 
297
  Reconstructed_image = gr.Image(label="Reconstructed")
298
  btn.click(fn=load_rec_image, outputs=Reconstructed_image)
299
  with gr.Row():
300
+ gr.Markdown("""Facial embeddings protection is a <span style='color:red; font-weight:bold'>MUST!</span> At **Suraksh.AI**, we protect facial embeddings using FHE.""")
301
 
302
  with gr.Row():
303
  gr.Markdown("### Step 3: πŸ”’ Encrypt reference embedding using FHE.")
 
352
  image_upload_auth = gr.Image(label="Upload a facial image.", type="pil", sources="upload")
353
  image_upload_auth.change(fn=crop_face_to_112x112, inputs=image_upload_auth, outputs=[image_input_auth,selectedImagePath_auth])
354
  with gr.Column():
355
+ # selectedImagePath_auth = gr.State()
356
  prob_gallery = gr.Gallery(value=example_images_auth, columns=3)
357
  prob_gallery.select(fn=get_selected_image_auth, inputs=None, outputs=[image_input_auth,selectedImagePath_auth])
358
  with gr.Column():
359
  selectedImage = gr.Image(type="pil", label="Probe facial image", interactive=False)
360
  image_input_auth.change(fn=lambda img: img, inputs=image_input_auth, outputs=selectedImage)
361
+
362
+
363
 
364
  with gr.Row():
365
  gr.Markdown("### Step 2: Generate probe facial embedding.")
366
  with gr.Row():
367
+ with gr.Column():
 
 
368
  key_button = gr.Button("Generate embedding")
369
  prob_emb_text = gr.JSON(label="Probe embedding")
370
  mode = gr.State("auth")