justin2341 commited on
Commit
e735dec
·
verified ·
1 Parent(s): 3fe116d

Update demo.py

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