-
Notifications
You must be signed in to change notification settings - Fork 11
/
facedb.py
60 lines (47 loc) · 1.86 KB
/
facedb.py
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
"""
* Author: Azmath Moosa
* Created: 30th July 2018
* Description: Python wrapper class for facedb.
Please launch and run the facedb app separately
* Dependencies: python requests, json
"""
import json
import requests
class FaceDBHandler():
def __init__(self, api="http://localhost:5100/", filename="facedb"):
print("Please make sure facedb is running in the background( ./facedb --serve )")
self.facedb_api = api
self.db_path = filename
def save_embedding(self, vec, meta):
endpt = self.facedb_api + "save_embedding"
body = {"embedding": vec, "meta":meta}
res = requests.post(endpt,json=body).json()
return res
def reindex(self):
endpt = self.facedb_api + "reindex"
res = requests.post(endpt, json={}).json()
return res["message"] == "ok"
def dump_database(self):
endpt = self.facedb_api + "dump_database"
res = requests.post(endpt, json={"filename":self.db_path}).json()
return res
def load_database(self):
endpt = self.facedb_api + "load_database"
res = requests.post(endpt, json={"filename":self.db_path}).json()
return res["message"] == "ok"
def clear_database(self):
endpt = self.facedb_api + "clear_database"
res = requests.post(endpt, json={}).json()
return res
def print_database(self):
endpt = self.facedb_api + "print_database"
res = requests.post(endpt, json={}).json()
return res
def search_database(self, vec):
endpt = self.facedb_api + "search_embedding"
res = requests.post(endpt, json={"embedding": vec.tolist()})
try:
print(res.text)
return res.json()
except:
return {"index":0, "distance":0.0}