#!/usr/bin/env python
import numpy as np
from utils.face_fetch import return_face
from pickle import load, dump
from utils.mlcode import get_embeddings

print "Get face : 1.from camera\t2.from image"
ch = raw_input("(1 or 2) : ")
new_face = return_face(mode=int(ch)-1)

if new_face is None:
    print "Invalid Input...Aborting!!!"
    exit(0)

face_embs = np.load("./faces/face_embs.npy")
with open("./faces/nameIds.pickle", "rb") as fh:
    names = load(fh)

new_name = raw_input("Enter name : ")
new_emb = get_embeddings(new_face)

names.append(new_name)
face_embs = np.append(face_embs, new_emb, axis=0)

np.save("./faces/face_embs.npy", face_embs)
with open("./faces/nameIds.pickle", "wb") as fh:
    dump(names, fh)

print "New Name Id '%s' added"%new_name
