def get_bot_response(): userText = request.args.get('msg') # print(userText) res = '' # try: datasetFile = open("./dataset/basic.txt", "r") except FileNotFoundError: # print("Bot> Oops! I am unable to locate \"" + datasetName + "\"") # add email return exit() paragraphs = [] for para in datasetFile.readlines(): if (len(para.strip()) > 0): paragraphs.append(para.strip()) drm = DRM(paragraphs, True, True) # greetPattern = re.compile("^\ *((hi+)|((good\ )?morning|evening|afternoon)|(he((llo)|y+)))\ *$", re.IGNORECASE) userQuery = userText if (not len(userQuery) > 0): # print(len(userQuery)) print("You need to ask something") # elif greetPattern.findall(userQuery): # response = "Hello!" else: pq = PQ(userQuery, True, False, True) response = drm.query(pq) res = ':' + response return res
def get_features(datasetFile:str): paragraphs = [] for para in datasetFile.split('\n'): if (len(para.strip()) > 0): paragraphs.append(para.strip()) # Processing Paragraphs drm = DRM(paragraphs, True, True) questions = ['experience','size'] answers = [] for i in TITLES: for j in TITLES[i]: userQuery = j pq = PQ(userQuery, True, False, True) response = drm.query(pq) if response != ' ': break else: continue break else: i = '' answers.append(i) for i in questions: userQuery = i pq = PQ(userQuery, True, False, True) # Get Response From Bot response = drm.query(pq) answers.append(response) return answers
def main(datasetName, use_word_embeddings): print("Bot> Please wait, while I am loading my dependencies") # Loading Dataset try: datasetFile = open(datasetName,"r", encoding="utf-8") except FileNotFoundError: print("Bot> Oops! I am unable to locate \"" + datasetName + "\"") exit() # Retrieving paragraphs : Assumption is that each paragraph in dataset is # separated by new line character paragraphs = [] for para in datasetFile.readlines(): if(len(para.strip()) > 0): paragraphs.append(para.strip()) # Loading Model modelName = datasetName.replace("dataset", "models").replace(".txt", ".h5") model = Word2Vec.load(modelName) # Processing Paragraphs if use_word_embeddings: drm = DRMWM(paragraphs, model, True, True) else: drm = DRM(paragraphs, True, True) print("Bot> Hey! I am ready. Ask me factoid based questions only :P") print("Bot> You can say me Bye anytime you want") # Greet Pattern greetPattern = re.compile("^\ *((hi+)|((good\ )?morning|evening|afternoon)|(he((llo)|y+)))\ *$",re.IGNORECASE) isActive = True while isActive: userQuery = input("You> ") if(not len(userQuery)>0): print("Bot> You need to ask something") elif greetPattern.findall(userQuery): response = "Hello!" elif userQuery.strip().lower() == "bye": response = "Bye Bye!" isActive = False else: # Proocess Question if use_word_embeddings: pq = PQWM(userQuery, model, True,False,True) else: pq = PQ(userQuery,True,False,True) # Get Response From Bot response =drm.query(pq) print("Bot>",response)
def retrievePara(datasetName): try: datasetFile = open(datasetName, "r") except FileNotFoundError: return "Topic {} not found. Go through the topics and pick one again.".format(''.join(datasetName.split('/')[-1:])) # print("Bot> Oops! I am unable to locate \"" + datasetName + "\"") # exit() # Retrieving paragraphs : Assumption is that each paragraph in dataset is # separated by new line character paragraphs = [] for para in datasetFile.readlines(): if (len(para.strip()) > 0): paragraphs.append(para.strip()) # Processing Paragraphs return DRM(paragraphs, True, True)
# Loading Dataset try: datasetFile = open(datasetName, "r") except FileNotFoundError: print("Bot> Oops! I am unable to locate \"" + datasetName + "\"") exit() # Retrieving paragraphs : Assumption is that each paragraph in dataset is # separated by new line character paragraphs = [] for para in datasetFile.readlines(): if (len(para.strip()) > 0): paragraphs.append(para.strip()) # Processing Paragraphs drm = DRM(paragraphs, True, True) print("Bot> Hey! I am ready. Ask me factoid based questions only :P") print("Bot> You can say me Bye anytime you want") # Greet Pattern greetPattern = re.compile( "^\ *((hi+)|((good\ )?morning|evening|afternoon)|(he((llo)|y+)))\ *$", re.IGNORECASE) isActive = True while isActive: userQuery = input("You> ") if (not len(userQuery) > 0): print("Bot> You need to ask something")
def main(): print("Bot> Please wait, Loading preferences from Home Base") #trainer() name = recognise() #datafile=input("Input Data File Name : ") try: datasetName = "dataset/" + name + ".txt" print(datasetName) except FileNotFoundError: print("Bot> Oops! I am unable to locate \"" + datasetName + "\"") print("Bot> Hey! I am ready. Ask me factoid based questions only :P") print("Bot> You can say me Bye anytime you want") greetPattern = re.compile( "^\ *((hi+)|((good\ )?morning|evening|afternoon)|(he((llo)|y+)))\ *$", re.IGNORECASE) isActive = True response = "Hello User" while isActive: name = recognise() if (name != '0'): datasetName = "dataset/" + name + ".txt" print(datasetName) try: datasetFile = open(datasetName, "r") except FileNotFoundError: print("Bot> Oops! I am unable to locate \"" + datasetName + "\"") datasetFile = open("dataset/1.txt", "r") #exit() paragraphs = [] try: for para in datasetFile.readlines(): if (len(para.strip()) > 0): paragraphs.append(para.strip()) drm = DRM(paragraphs, True, True) except: print("Bot> Oops! Error in reading dataset") continue userQuery = input("You> ") if (not len(userQuery) > 0): print("Bot> You need to ask something") elif greetPattern.findall(userQuery): response = "Hello!" elif userQuery.strip().lower() == "bye": response = "Bye Bye!" isActive = False elif userQuery.strip().lower() == "train faces": trainer() elif userQuery.strip().lower() == "new": detect() elif userQuery.strip().lower() == "train": trainer() elif userQuery.strip().lower() == "new user": detect() trainer() elif userQuery.strip().lower() == "detect faces": recognise1() elif userQuery.strip().lower() == "speech": try: userQuery = get_audio() except: print("Error Recognizing Audio") continue print("User Said : ", userQuery) if greetPattern.findall(userQuery): response = "Hello!" else: print(name, " said : ", userQuery) pq = PQ(userQuery, True, False, True) response = drm.query(pq) else: pq = PQ(userQuery, True, False, True) response = drm.query(pq) print("Bot>", response)