Esempio n. 1
0
 def handleMessage(self):
     # echo message back to client
     message = self.data
     print(message)
     response = get_response(message)
     print(response)
     self.sendMessage(response)
Esempio n. 2
0
def get_bot_response():
    user_text = request.args.get('msg')

    if utils.chatbot_enabled:
        if user_text.lower() == "quit":
            utils.chatbot_enabled =False
            return translate("Bye")
        else:
            respo = translate(str(chatbot.get_response(translate(user_text))))
            if respo == "":
                respo = "Sorry, Data not found.Please be more precise"
            print("response: ", respo)
            return respo
    elif (user_text.strip() == "Help") or (user_text.strip() == "help") or (user_text.strip() == "Help!"):
        return str('Ok, here is a link to search more: <a href=\'https://www.google.com\'>www.google.com</a>')
    elif user_text.isnumeric():
        if int(user_text) == 6:
            utils.chatbot_enabled = True
            return translate("Hi, ask any question relate to Covid. For Quiting this chatbot Enter 'Quit'")
        # elif int(user_text) == 8:
        #     # return init_speech_recogition()
        #     utils.chatbot_enabled = True
        #     return translate("Hi, ask any question relate to Covid. For Quiting this chatbot Enter 'Quit'")
        elif (int(user_text) <= len(dataset.dataset)) and (int(user_text) > -1):
            return translate(str(utils.remove_breakline(dataset.dataset[int(user_text)])))
        else:
            return translate(str(utils.remove_breakline(dataset.wrong_input)))
    elif user_text.lower() in (name.lower() for name in dataset.languages):
        dataset.s_lang = dataset.languages_code[[name.lower() for name in dataset.languages].index(user_text.lower())]
        return translate(dataset.lang_changed_text)
    else:
        return str("Wrong input.")
Esempio n. 3
0
    def respond(self, str):
        failure_count=0
        """
        Generate a response to the user input.

        :type str: str
        :param str: The string to be mapped
        :rtype: str
        """

        # check each pattern
        for (pattern, response) in self._pairs:
            match = pattern.match(str)

            # did the pattern match?
            if match:
                resp = random.choice(response)  # pick a random response
                resp = self._wildcards(resp, match)  # process wildcards

                # fix munged punctuation at the end
                if resp[-2:] == '?.':
                    resp = resp[:-2] + '.'
                if resp[-2:] == '??':
                    resp = resp[:-2] + '?'
                return resp

            else :
                failure_count=failure_count + 1
                if failure_count<=3:
                    resp = get_response(str)
                    return resp

                else :
                    pass
Esempio n. 4
0
def message_rec(msg):
    #global user_messages
    print("message received: " + msg)
    #user_messages+=msg+"\n" #a try to bring a conversation into a certain context with smoother changes between topics
    reply = chatbot.get_response(msg, genre_model)
    #user_messages+=reply+"\n" #a try to bring a conversation into a certain context with smoother changes between topics
    emit('reply', reply)
Esempio n. 5
0
def setName():
    if request.method == 'POST':
        posted_data = request.get_json()
        data = posted_data['input']
        response, query_comb = get_response([data])
        json_resp = make_json(response, query_comb)
        # print(response)
        return json_resp
 def handleMessage(self):
     # echo message back to client
     message = self.data
     #        handler = ChatBotGraph()
     #        response = handler.chat_main(message)
     #response = self.chat_main(message)
     response = get_response(message)
     self.sendMessage(response)
Esempio n. 7
0
 def handleMessage(self):
     # echo message back to client
     print(self.address, 'start')
     message = self.data
     print(self.address, 'step1:' + message)
     response = get_response(message)
     print(self.address, 'step4:' + response)
     self.sendMessage(response)
     print(self.address, 'handle')
Esempio n. 8
0
def handle_summary_parsing(summary_text, user_profile):
    print("Attempting to parse text...")
    results = parse_summary(summary_text, user_profile)

    if results is not None and len(results) > 0:
        glory_walls = save_glory_walls(results, user_profile)
        render_to_wiki(Category.select(), UTOPIA_AGE)
        send_response(glory_walls, user_profile)
    else:
        response = chatbot.get_response(summary_text)
        constants.slack.chat.post_message(OUTPUT_CHANNEL,
                                          response,
                                          as_user=True)
Esempio n. 9
0
async def send_message(message: Message):
    if 'sess' not in items or 'wv_model' not in items or 'models' not in items or 'answer_sets' not in items:
        raise HTTPException(status_code=500,
                            detail="Server Error - chatbot couldn't load!")
    if not (message.mode == 'friend' or message.mode == 'professional'
            or message.mode == 'comic'):
        raise HTTPException(
            status_code=400,
            detail="Mode can only be 'friend', 'professional', or 'comic'.")
    return {
        "answer":
        get_response(items['sess'], items['wv_model'], items['models'],
                     items['answer_sets'], message.message, message.mode)
    }
 def handleMessage(self):
     message = self.data
     response = get_response(message)
     print(response)
     self.sendMessage(response)
Esempio n. 11
0
 def handleMessage(self):
     # echo message back to client
     message = self.data
     response = get_response(message, self)
     self.sendMessage(response)
transcript_q = recognizer.callback.transcript_q

modes = ['predict', 'tts', 'stt', 'chat']

if __name__ == '__main__':
    while True:
        try:
            mode = input("MODE: ").lower().strip()
            while mode not in modes:
                mode = input("MODE: ").lower().strip()

            if mode == 'stt':
                try:
                    recognizer.start()
                    while recognizer.thread.is_alive():
                        pass
                finally:
                    recognizer.close()
                    quit()

            while True:
                if mode == 'predict':
                    print(predict_text(input_("> ").lower()))
                elif mode == 'tts':
                    engine.say(input_("> "))
                    engine.runAndWait()
                elif mode == 'chat':
                    print("BOT: " + str(get_response(input_("MAX: ").lower())))
        except KeyboardInterrupt:
            pass