tomas-gajarsky commited on
Commit
65a4898
1 Parent(s): 636e0ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -22
app.py CHANGED
@@ -3,7 +3,6 @@ import json
3
  import argparse
4
  import operator
5
  import gradio as gr
6
- import torch
7
  import torchvision
8
  from typing import Tuple, Dict
9
  from facetorch import FaceAnalyzer
@@ -25,26 +24,6 @@ cfg = OmegaConf.load(args.path_conf)
25
  analyzer = FaceAnalyzer(cfg.analyzer)
26
 
27
 
28
- def tensor_to_list(tensor: torch.Tensor) -> list:
29
- return tensor.tolist()
30
-
31
- def dataclass_to_dict(obj):
32
- if hasattr(obj, "__dataclass_fields__"):
33
- return asdict(obj)
34
- return obj
35
-
36
- def image_data_to_json(image_data: ImageData) -> str:
37
- # Convert tensors to lists
38
- image_data.img = tensor_to_list(image_data.img)
39
- image_data.tensor = tensor_to_list(image_data.tensor)
40
-
41
- # Convert dataclass to dictionary
42
- data_dict = dataclass_to_dict(image_data)
43
-
44
- # Convert dictionary to JSON string
45
- json_str = json.dumps(data_dict, indent=4, default=dataclass_to_dict)
46
- return json_str
47
-
48
  def gen_sim_dict_str(response: ImageData, pred_name: str = "verify", index: int = 0)-> str:
49
  if len(response.faces) > 0:
50
  base_emb = response.faces[index].preds[pred_name].logits
@@ -71,7 +50,7 @@ def inference(path_image: str) -> Tuple:
71
  fer_dict_str = str({face.indx: face.preds["fer"].label for face in response.faces})
72
  au_dict_str = str({face.indx: face.preds["au"].other["multi"] for face in response.faces})
73
  deepfake_dict_str = str({face.indx: face.preds["deepfake"].label for face in response.faces})
74
- response_str = image_data_to_json(response)
75
 
76
  sim_dict_str_embed = gen_sim_dict_str(response, pred_name="embed", index=0)
77
  sim_dict_str_verify = gen_sim_dict_str(response, pred_name="verify", index=0)
 
3
  import argparse
4
  import operator
5
  import gradio as gr
 
6
  import torchvision
7
  from typing import Tuple, Dict
8
  from facetorch import FaceAnalyzer
 
24
  analyzer = FaceAnalyzer(cfg.analyzer)
25
 
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  def gen_sim_dict_str(response: ImageData, pred_name: str = "verify", index: int = 0)-> str:
28
  if len(response.faces) > 0:
29
  base_emb = response.faces[index].preds[pred_name].logits
 
50
  fer_dict_str = str({face.indx: face.preds["fer"].label for face in response.faces})
51
  au_dict_str = str({face.indx: face.preds["au"].other["multi"] for face in response.faces})
52
  deepfake_dict_str = str({face.indx: face.preds["deepfake"].label for face in response.faces})
53
+ response_str = str(response)
54
 
55
  sim_dict_str_embed = gen_sim_dict_str(response, pred_name="embed", index=0)
56
  sim_dict_str_verify = gen_sim_dict_str(response, pred_name="verify", index=0)