def main(): # Determine if valid number of arguments are found if len(sys.argv[1:]) == 0: print('driver.py <image file>') sys.exit(1) # Get the image filepath imgFp = sys.argv[1] # On this specific instance use the /tests folder and check against all of the test cases if imgFp == 'ALL': testdir = 'tests' for fp in os.listdir(testdir): # Only handle .jpg and .png if fp.endswith('.jpg') or fp.endswith('.png'): name = fp fp = os.path.join(testdir, fp) print(name, 'is found to be a', find_most_similar(Image.open(fp))) sys.exit(0) # See if file exists if not os.path.exists(imgFp): print(imgFp, 'file does not exist!') sys.exit(1) # Load image img = Image.open(imgFp) # Find most similar image print(find_most_similar(img))
def answer_question(text): question = text answer = find_most_similar(question) final_answer = '' final_question = '' if answer['score'] > 0.6: print(answer['score']) final_answer = answer['answer'] final_question = answer['question'] return final_answer, final_question
def allow_question(self): # Check for event stack potential_event = None if (len(self.event_stack)): potential_event = self.event_stack.pop() if potential_event: text = input("Pregunta: ") potential_event.handle_response(text, self) else: text = input("Respuesta: ") answer = self.pre_built_responses_or_none(text) if not answer: answer = find_most_similar(text) self.answer_question(answer, text)
def search_answer(self,text): # Check for event stack potential_event = None if(len(self.event_stack)): potential_event = self.event_stack.pop() if potential_event: return potential_event.handle_response(text, self) else: answer = self.pre_built_responses_or_none(text) if not answer: answer = similarity.find_most_similar(text,self.sim,self.cos) return self.answer_question(answer, text) else: return answer
def response(user_response, raw_response, detected_lang, category): query = user_response answer = find_most_similar(category, query) if (answer['score'] > confidence_score['min_score']): # set off event asking if the response question is what they were looking for print("\nBest-fit question: %s (Score: %s)\nAnswer: %s\n" % (answer['question'], answer['score'], answer['answer'])) SoliBot_response = answer['answer'] return SoliBot_response else: try: #Sending Un-Answered Query to Database sql = "INSERT INTO unanswered (un_que_lang, un_que_cat, un_que_en) VALUES (%s, %s, %s)" val = (raw_response, detected_lang, user_response) cursor.execute(sql, val) faqdb.commit() print(cursor.rowcount, "Un-Answered Question pushed to FAQ Database") SoliBot_response = "I'm sorry i didn't catch that! \nCould you please rephrase that query?" except: SoliBot_response = "I'm sorry i didn't catch that! \nCould you please rephrase that query?" return SoliBot_response