-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
137 lines (109 loc) · 4.01 KB
/
main.py
File metadata and controls
137 lines (109 loc) · 4.01 KB
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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import os
import shutil
from dotenv import load_dotenv
from tkinter import Tk
from tkinter.filedialog import askopenfilenames
from pymongo import MongoClient
import embedding_gen as embedding_gen
import intent_classifier as intent_classifier
import offline_speech_rec as offline_speech_rec
import face_detector as face_detector
load_dotenv()
db_url = os.getenv("DB_URL", "mongodb://localhost:27017/")
relative_validator = {
"$jsonSchema": {
"bsonType": "object",
"required": ["name", "relationship", "address", "gender"],
"properties": {
"name": {
"bsonType": "string",
"description": "name is required"
},
"relationship": {
"bsonType": "string", "description": "relationship is required"
},
"last_meet": {
"bsonType": "date",
"description": "last_meet is required"
},
"address": {
"bsonType": "string",
"description": "address is required"
},
"gender" : {
"bsonType" : "string",
"description" : "gender is required"
}
}
}
}
def insert_relative(name, address, relationship, gender):
objectid = ""
print(db_url)
client = MongoClient(db_url)
db = client.memory_lane
try:
db.create_collection("relatives")
except Exception as e:
print(e)
db.command("collMod", "relatives", validator=relative_validator)
relatives = db.relatives
relative = {"name": name, "relationship": relationship, "address": address, "gender" : gender}
try:
result = relatives.insert_one(relative)
objectid = result.inserted_id
except Exception as e:
print(e)
return objectid
def copy_images(destination):
# Open a file dialog box to select the image files
root = Tk()
root.withdraw()
root.attributes('-topmost', True)
files = askopenfilenames(title='Select image files', filetypes=[('Image files', '*.jpg;*.jpeg;*.png;*.gif')])
# Copy the selected images to the destination folder
if not os.path.exists(destination):
os.makedirs(destination)
num_copied = 0
for file in files:
filename = os.path.basename(file)
shutil.copy(file, os.path.join(destination, filename))
num_copied += 1
print(f'{num_copied} images have been copied to {destination}.')
if __name__ == '__main__':
while True:
print("Assistance Bot Welcomes You!!")
print("Please select the option you want to perform")
print("1. Add a new relative")
print("2. Start recognition")
print("3. Exit")
options = input("Input your Choice: ")
if options == "1":
print("Add a new relative")
print("Please enter the following details")
name = input("Name: ")
address = input("Address: ")
relationship = input("Relationship: ")
gender = input("Gender: ")
objectid = insert_relative(name,address,relationship,gender)
print("Please upload the images of the relative")
copy_images(f"images/{objectid}")
print("Generating embeddings")
embedding_gen.get_embeddings()
face_detector.updateEmbeddings()
elif options == "2":
print("Choose mode: ")
print("1. Voice")
print("2. Text")
mode = input("Input your Choice: ")
if mode == "1":
print("Voice mode activated")
offline_speech_rec.recognize_speech()
elif mode == "2":
print("Text mode activated")
intent_classifier.text_mode()
elif options == "3":
print("Exiting")
break
else :
print("Invalid Choice")