justin2341 commited on
Commit
1d8e88d
·
verified ·
1 Parent(s): 561fba7

Update demo.py

Browse files
Files changed (1) hide show
  1. demo.py +42 -39
demo.py CHANGED
@@ -51,47 +51,50 @@ def compare_face(frame1, frame2):
51
 
52
  if result.ok:
53
  json_result = result.json()
 
 
 
 
 
54
 
55
- if json_result.get("resultCode") != "Ok":
56
- return json_result.get("resultCode")
57
-
58
- html = ""
59
- faces1 = json_result.get("faces1", {})
60
- faces2 = json_result.get("faces2", {})
61
- results = json_result.get("results", {})
62
-
63
- for result in results:
64
- score = result.get('score')
65
- face1_idx = result.get('face1')
66
- face2_idx = result.get('face2')
67
-
68
- face_image1 = face_crop(image1, faces1[face1_idx])
69
- 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"))
70
-
71
- face_image2 = face_crop(image2, faces2[face2_idx])
72
- 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"))
73
-
74
- 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>'
75
- if score > 0.67:
76
- 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>'
77
-
78
- item_value = ('<div style="align-items: center; gap: 10px; display: flex; flex-direction: column;">'
79
- '<div style="display: flex; align-items: center; gap: 20px;">'
80
- '{face_value1}'
81
- '{match_icon}'
82
- '{face_value2}'
83
- '</div>'
84
- '<div style="text-align: center; margin-top: 10px;">'
85
- 'Score: {score}'
86
- '</div>'
87
- '</div>'
88
- ).format(face_value1=face_value1, face_value2=face_value2, match_icon=match_icon, score=f"{score:.2f}")
89
- html += item_value
90
- html += '<hr style="border: 1px solid #C0C0C0; margin: 10px 0;"/>'
91
-
92
- return html
93
  else:
94
- return result.text
 
95
 
96
  with gr.Blocks(css=".gradio-container {background-color: #F4E5E0}") as demo:
97
  with gr.Row():
 
51
 
52
  if result.ok:
53
  json_result = result.json()
54
+
55
+ return json_result
56
+
57
+ # if json_result.get("resultCode") != "Ok":
58
+ # return json_result.get("resultCode")
59
 
60
+ # html = ""
61
+ # faces1 = json_result.get("faces1", {})
62
+ # faces2 = json_result.get("faces2", {})
63
+ # results = json_result.get("results", {})
64
+
65
+ # for result in results:
66
+ # score = result.get('score')
67
+ # face1_idx = result.get('face1')
68
+ # face2_idx = result.get('face2')
69
+
70
+ # face_image1 = face_crop(image1, faces1[face1_idx])
71
+ # 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"))
72
+
73
+ # face_image2 = face_crop(image2, faces2[face2_idx])
74
+ # 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"))
75
+
76
+ # 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>'
77
+ # if score > 0.67:
78
+ # 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>'
79
+
80
+ # item_value = ('<div style="align-items: center; gap: 10px; display: flex; flex-direction: column;">'
81
+ # '<div style="display: flex; align-items: center; gap: 20px;">'
82
+ # '{face_value1}'
83
+ # '{match_icon}'
84
+ # '{face_value2}'
85
+ # '</div>'
86
+ # '<div style="text-align: center; margin-top: 10px;">'
87
+ # 'Score: {score}'
88
+ # '</div>'
89
+ # '</div>'
90
+ # ).format(face_value1=face_value1, face_value2=face_value2, match_icon=match_icon, score=f"{score:.2f}")
91
+ # html += item_value
92
+ # html += '<hr style="border: 1px solid #C0C0C0; margin: 10px 0;"/>'
93
+
94
+ # return html
 
 
 
95
  else:
96
+ return "abcdeef"
97
+ # return result.text
98
 
99
  with gr.Blocks(css=".gradio-container {background-color: #F4E5E0}") as demo:
100
  with gr.Row():