forked from exadel-inc/CompreFace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtutorial_demo.html
70 lines (62 loc) · 2.24 KB
/
tutorial_demo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function saveNewImageToFaceCollection(elem) {
let subject = encodeURIComponent(document.getElementById("subject").value);
let apiKey = document.getElementById("apiKey").value;
let formData = new FormData();
let photo = elem.files[0];
formData.append("file", photo);
fetch('http://localhost:8000/api/v1/recognition/faces/?subject=' + subject,
{
method: "POST",
headers: {
"x-api-key": apiKey
},
body: formData
}
).then(r => r.json()).then(
function (data) {
console.log('New example was saved', data);
})
.catch(function (error) {
alert('Request failed: ' + JSON.stringify(error));
});
}
function recognizeFace(elem) {
let apiKey = document.getElementById("apiKey").value;
let formData = new FormData();
let photo = elem.files[0];
formData.append("file", photo);
fetch('http://localhost:8000/api/v1/recognition/recognize',
{
method: "POST",
headers: {
"x-api-key": apiKey
},
body: formData
}
).then(r => r.json()).then(
function (data) {
document.getElementById("result").innerHTML = JSON.stringify(data);
})
.catch(function (error) {
alert('Request failed: ' + JSON.stringify(error));
});
}
</script>
<title>test</title>
</head>
<body>
<label for="apiKey">API key:</label><input id="apiKey" />
<div></div>
<label for="subject">Subject:</label><input id="subject" />
<div>Click to add photo:</div>
<input type=file id="newFace" onchange="saveNewImageToFaceCollection(this)" />
<div>Click to recognize photo</div>
<input type=file id="recognizeFace" onchange="recognizeFace(this)" />
<div>Result:</div>
<div id="result"></div>
</body>
</html>