Spaces:
Runtime error
Runtime error
Update
Browse files- app.py +21 -3
- gradio/demo.py +4 -26
app.py
CHANGED
@@ -112,8 +112,17 @@ def compare_face():
|
|
112 |
result = "different person!"
|
113 |
|
114 |
status = "ok"
|
115 |
-
response = jsonify(
|
116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
response.status_code = 200
|
118 |
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
119 |
return response
|
@@ -189,7 +198,16 @@ def coompare_face_base64():
|
|
189 |
result = "different person!"
|
190 |
|
191 |
status = "ok"
|
192 |
-
response = jsonify(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
response.status_code = 200
|
194 |
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
195 |
return response
|
|
|
112 |
result = "different person!"
|
113 |
|
114 |
status = "ok"
|
115 |
+
response = jsonify(
|
116 |
+
{
|
117 |
+
"status": status,
|
118 |
+
"data": {
|
119 |
+
"result": result,
|
120 |
+
"similarity": float(similarity),
|
121 |
+
"face1": {"x1": int(faceRect1[0]), "y1": int(faceRect1[1]), "x2": int(faceRect1[2]), "y2" : int(faceRect1[3])},
|
122 |
+
"face2": {"x1": int(faceRect2[0]), "y1": int(faceRect2[1]), "x2": int(faceRect2[2]), "y2" : int(faceRect2[3])},
|
123 |
+
}
|
124 |
+
})
|
125 |
+
|
126 |
response.status_code = 200
|
127 |
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
128 |
return response
|
|
|
198 |
result = "different person!"
|
199 |
|
200 |
status = "ok"
|
201 |
+
response = jsonify(
|
202 |
+
{
|
203 |
+
"status": status,
|
204 |
+
"data": {
|
205 |
+
"result": result,
|
206 |
+
"similarity": float(similarity),
|
207 |
+
"face1": {"x1": int(faceRect1[0]), "y1": int(faceRect1[1]), "x2": int(faceRect1[2]), "y2" : int(faceRect1[3])},
|
208 |
+
"face2": {"x1": int(faceRect2[0]), "y1": int(faceRect2[1]), "x2": int(faceRect2[2]), "y2" : int(faceRect2[3])},
|
209 |
+
}
|
210 |
+
})
|
211 |
response.status_code = 200
|
212 |
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
213 |
return response
|
gradio/demo.py
CHANGED
@@ -7,28 +7,6 @@ def compare_face(frame1, frame2):
|
|
7 |
files = {'image1': open(frame1, 'rb'), 'image2': open(frame2, 'rb')}
|
8 |
|
9 |
r = requests.post(url=url, files=files)
|
10 |
-
print("==================", r.json())
|
11 |
-
'''
|
12 |
-
html = None
|
13 |
-
faces = None
|
14 |
-
|
15 |
-
compare_result = r.json().get('compare_result')
|
16 |
-
compare_similarity = r.json().get('compare_similarity')
|
17 |
-
|
18 |
-
html = ("<table>"
|
19 |
-
"<tr>"
|
20 |
-
"<th>Face State</th>"
|
21 |
-
"<th>Value</th>"
|
22 |
-
"</tr>"
|
23 |
-
"<tr>"
|
24 |
-
"<td>Result</td>"
|
25 |
-
"<td>{compare_result}</td>"
|
26 |
-
"</tr>"
|
27 |
-
"<tr>"
|
28 |
-
"<td>Similarity</td>"
|
29 |
-
"<td>{compare_similarity}</td>"
|
30 |
-
"</tr>"
|
31 |
-
"</table>".format(compare_result=compare_result, compare_similarity=compare_similarity))
|
32 |
|
33 |
try:
|
34 |
image1 = Image.open(frame1)
|
@@ -102,8 +80,8 @@ def compare_face(frame1, frame2):
|
|
102 |
|
103 |
except:
|
104 |
pass
|
105 |
-
|
106 |
-
return r.json()
|
107 |
|
108 |
with gr.Blocks() as demo:
|
109 |
gr.Markdown(
|
@@ -124,9 +102,9 @@ with gr.Blocks() as demo:
|
|
124 |
gr.Examples(['gradio/examples/3.jpg', 'gradio/examples/4.jpg'],
|
125 |
inputs=compare_face_input2)
|
126 |
with gr.Column():
|
127 |
-
|
128 |
compare_result_output = gr.JSON(label='Result')
|
129 |
|
130 |
-
compare_face_button.click(compare_face, inputs=[compare_face_input1, compare_face_input2], outputs=compare_result_output)
|
131 |
|
132 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
7 |
files = {'image1': open(frame1, 'rb'), 'image2': open(frame2, 'rb')}
|
8 |
|
9 |
r = requests.post(url=url, files=files)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
try:
|
12 |
image1 = Image.open(frame1)
|
|
|
80 |
|
81 |
except:
|
82 |
pass
|
83 |
+
|
84 |
+
return [r.json(), faces]
|
85 |
|
86 |
with gr.Blocks() as demo:
|
87 |
gr.Markdown(
|
|
|
102 |
gr.Examples(['gradio/examples/3.jpg', 'gradio/examples/4.jpg'],
|
103 |
inputs=compare_face_input2)
|
104 |
with gr.Column():
|
105 |
+
compare_face_output = gr.Image(type="pil", height=150)
|
106 |
compare_result_output = gr.JSON(label='Result')
|
107 |
|
108 |
+
compare_face_button.click(compare_face, inputs=[compare_face_input1, compare_face_input2], outputs=[compare_face_output, compare_result_output])
|
109 |
|
110 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|