justin2341 commited on
Commit
69caf24
·
verified ·
1 Parent(s): bd054df

Update demo.py

Browse files
Files changed (1) hide show
  1. demo.py +29 -27
demo.py CHANGED
@@ -60,38 +60,40 @@ def compare_face(frame1, frame2):
60
  image2 = Image.open(frame2)
61
 
62
  html = ""
63
- faces1 = json_result.get("faces1", {})
64
- faces2 = json_result.get("faces2", {})
65
- results = json_result.get("results", {})
 
 
66
 
67
- for result in results:
68
- similarity = result.get('similarity')
69
- face1_idx = result.get('face1')
70
- face2_idx = result.get('face2')
71
 
72
- face_image1 = face_crop(image1, faces1[face1_idx])
73
- face_value1 = ('<img src="data:image/png;base64,{base64_image}" style="width: 100px; height: auto; object-fit: contain;"/>').format(base64_image=pil_image_to_base64(face_image1, format="PNG"))
74
 
75
- face_image2 = face_crop(image2, faces2[face2_idx])
76
- face_value2 = ('<img src="data:image/png;base64,{base64_image}" style="width: 100px; height: auto; object-fit: contain;"/>').format(base64_image=pil_image_to_base64(face_image2, format="PNG"))
77
 
78
- match_icon = '<svg fill="red" width="19" height="32" viewBox="0 0 19 32"><path d="M0 13.92V10.2H19V13.92H0ZM0 21.64V17.92H19V21.64H0Z"></path><path d="M14.08 0H18.08L5.08 32H1.08L14.08 0Z"></path></svg>'
79
- if similarity > 0.67:
80
- match_icon = '<svg fill="green" width="19" height="32" viewBox="0 0 19 32"><path d="M0 13.9202V10.2002H19V13.9202H0ZM0 21.6402V17.9202H19V21.6402H0Z"></path></svg>'
81
 
82
- item_value = ('<div style="align-items: center; gap: 10px; display: flex; flex-direction: column;">'
83
- '<div style="display: flex; align-items: center; gap: 20px;">'
84
- '{face_value1}'
85
- '{match_icon}'
86
- '{face_value2}'
87
- '</div>'
88
- '<div style="text-align: center; margin-top: 10px;">'
89
- 'Similarity: {similarity}'
90
- '</div>'
91
- '</div>'
92
- ).format(face_value1=face_value1, face_value2=face_value2, match_icon=match_icon, similarity=f"{similarity:.2f}")
93
- html += item_value
94
- html += '<hr style="border: 1px solid #C0C0C0; margin: 10px 0;"/>'
95
 
96
  return html
97
  except:
 
60
  image2 = Image.open(frame2)
61
 
62
  html = ""
63
+ # faces1 = json_result.get("faces1", {})
64
+ html = json.dumps(json_result, indent=4)
65
+
66
+ # faces2 = json_result.get("faces2", {})
67
+ # results = json_result.get("results", {})
68
 
69
+ # for result in results:
70
+ # similarity = result.get('similarity')
71
+ # face1_idx = result.get('face1')
72
+ # face2_idx = result.get('face2')
73
 
74
+ # face_image1 = face_crop(image1, faces1[face1_idx])
75
+ # face_value1 = ('<img src="data:image/png;base64,{base64_image}" style="width: 100px; height: auto; object-fit: contain;"/>').format(base64_image=pil_image_to_base64(face_image1, format="PNG"))
76
 
77
+ # face_image2 = face_crop(image2, faces2[face2_idx])
78
+ # face_value2 = ('<img src="data:image/png;base64,{base64_image}" style="width: 100px; height: auto; object-fit: contain;"/>').format(base64_image=pil_image_to_base64(face_image2, format="PNG"))
79
 
80
+ # match_icon = '<svg fill="red" width="19" height="32" viewBox="0 0 19 32"><path d="M0 13.92V10.2H19V13.92H0ZM0 21.64V17.92H19V21.64H0Z"></path><path d="M14.08 0H18.08L5.08 32H1.08L14.08 0Z"></path></svg>'
81
+ # if similarity > 0.67:
82
+ # match_icon = '<svg fill="green" width="19" height="32" viewBox="0 0 19 32"><path d="M0 13.9202V10.2002H19V13.9202H0ZM0 21.6402V17.9202H19V21.6402H0Z"></path></svg>'
83
 
84
+ # item_value = ('<div style="align-items: center; gap: 10px; display: flex; flex-direction: column;">'
85
+ # '<div style="display: flex; align-items: center; gap: 20px;">'
86
+ # '{face_value1}'
87
+ # '{match_icon}'
88
+ # '{face_value2}'
89
+ # '</div>'
90
+ # '<div style="text-align: center; margin-top: 10px;">'
91
+ # 'Similarity: {similarity}'
92
+ # '</div>'
93
+ # '</div>'
94
+ # ).format(face_value1=face_value1, face_value2=face_value2, match_icon=match_icon, similarity=f"{similarity:.2f}")
95
+ # html += item_value
96
+ # html += '<hr style="border: 1px solid #C0C0C0; margin: 10px 0;"/>'
97
 
98
  return html
99
  except: