justin2341 commited on
Commit
831cf0c
·
verified ·
1 Parent(s): db99fd4

Update demo.py

Browse files
Files changed (1) hide show
  1. demo.py +42 -46
demo.py CHANGED
@@ -49,53 +49,49 @@ def compare_face(frame1, frame2):
49
  files = {'file1': file1, 'file2': file2}
50
  result = requests.post(url=url, files=files)
51
 
52
- return "abcdef"
53
-
54
- # print(result)
55
- # if result.ok:
56
- # json_result = result.json()
57
- # printf("json_result", json_result)
58
 
59
- # if json_result.get("resultCode") != "Ok":
60
- # return [json_result.get("resultCode"), json_result]
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
- # score = result.get('score')
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 score > 0.7:
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
- # 'Score: {score}'
90
- # '</div>'
91
- # '</div>'
92
- # ).format(face_value1=face_value1, face_value2=face_value2, match_icon=match_icon, score=f"{score:.2f}")
93
- # html += item_value
94
- # html += '<hr style="border: 1px solid #C0C0C0; margin: 10px 0;"/>'
95
-
96
- # return html
97
- # else:
98
- # return result.text
99
 
100
  with gr.Blocks(css=".gradio-container {background-color: #F4E5E0}") as demo:
101
  with gr.Row():
 
49
  files = {'file1': file1, 'file2': file2}
50
  result = requests.post(url=url, files=files)
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.7:
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():