tomas-gajarsky commited on
Commit
ce805af
·
1 Parent(s): eb252ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -25,13 +25,18 @@ def inference(path_image):
25
  deepfake_dict_str = str({face.indx: face.preds["deepfake"].label for face in response.faces})
26
  response_str = str(response)
27
 
28
- out_tuple = (pil_image, fer_dict_str, deepfake_dict_str, response_str)
 
 
 
 
 
29
  return out_tuple
30
 
31
 
32
  title = "facetorch"
33
- description = "Demo for facetorch, a Python library that can detect faces and analyze facial features using deep neural networks. The goal is to gather open sourced face analysis models from the community and optimize them for performance using TorchScrip. Try selecting one of the example images or upload your own."
34
- article = "<p style='text-align: center'><a href='https://github.com/tomas-gajarsky/facetorch' target='_blank'>Github Repo</a></p>"
35
 
36
  demo=gr.Interface(
37
  inference,
@@ -39,6 +44,7 @@ demo=gr.Interface(
39
  [gr.outputs.Image(type="pil", label="Output"),
40
  gr.outputs.Textbox(label="Facial Expression Recognition"),
41
  gr.outputs.Textbox(label="DeepFake Detection"),
 
42
  gr.outputs.Textbox(label="Response")],
43
  title=title,
44
  description=description,
 
25
  deepfake_dict_str = str({face.indx: face.preds["deepfake"].label for face in response.faces})
26
  response_str = str(response)
27
 
28
+ base_emb = response.faces[0].preds["verify"].logits
29
+ sim_dict = {face.indx: cosine_similarity(base_emb, face.preds["verify"].logits, dim=0).item() for face in response.faces}
30
+ sim_dict_sort = dict(sorted(sim_dict.items(), key=operator.itemgetter(1),reverse=True))
31
+ sim_dict_sort_str = str(sim_dict_sort)
32
+
33
+ out_tuple = (pil_image, fer_dict_str, deepfake_dict_str, sim_dict_sort_str, response_str)
34
  return out_tuple
35
 
36
 
37
  title = "facetorch"
38
+ description = "Demo of facetorch, a Python library that can detect faces and analyze facial features using deep neural networks. The goal is to gather open-sourced face analysis models from the community and optimize them for performance using TorchScrip. Try selecting one of the example images or upload your own."
39
+ article = "<p style='text-align: center'><a href='https://github.com/tomas-gajarsky/facetorch' target='_blank'>facetorch GitHub repository</a></p>"
40
 
41
  demo=gr.Interface(
42
  inference,
 
44
  [gr.outputs.Image(type="pil", label="Output"),
45
  gr.outputs.Textbox(label="Facial Expression Recognition"),
46
  gr.outputs.Textbox(label="DeepFake Detection"),
47
+ gr.outputs.Textbox(label="Cosine similarity on Face Verification Embeddings"),
48
  gr.outputs.Textbox(label="Response")],
49
  title=title,
50
  description=description,