Spaces:
Running
Running
Update demo.py
Browse files
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 |
-
|
53 |
-
|
54 |
-
# print(result)
|
55 |
-
# if result.ok:
|
56 |
-
# json_result = result.json()
|
57 |
-
# printf("json_result", json_result)
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
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():
|