def main():
    chatbot = Chatbot()
    while True:
        file = open("view.txt", "w")
        MyEncoder().encode(chatbot)
        file.write(json.dumps(chatbot, cls=MyEncoder, indent=4))
        file.close()

        file = open("AnswerList.txt", "w")
        i = 0
        for answer in chatbot.memory.actions:
            file.write(str(i) + ". " + answer + "\n")
            i = i + 1
        file.close()

        timestamp = time.strftime('%d %b %H:%M:%S', time.localtime())
        question = input(timestamp + "\tYou: ")
        if question == 'E':
            break
        elif question == 'I':
            filename = input("Please input the filename: ")
            chatbot.import_file(filename)
        elif question == 'X':
            filepath = input("Please input the path")
            filepath += "history.csv"
            chatbot.export_history(filepath)
        else:
            answer, outtime = chatbot.chat(question, timestamp)
            print(outtime + "\tChatbot: " + answer)
            #print("I am safe: ", chatbot.workMemory.action)
            while True:
                operation = input("Your operation: ")
                if operation == 'E' or operation == 'e':
                    #print("I am safe: ", chatbot.workMemory.action)
                    print("\n\n")
                    break
                if operation == 'C' or operation == 'c':
                    change = input("New answer: ")
                    chatbot.change(change)
                if operation == 'L' or operation == 'l':
                    chatbot.like()
                if operation == 'A' or operation == 'a':
                    print(chatbot.analysis())
        #print("I am safe: ", chatbot.workMemory.action)
        patternAnswer(chatbot)
Example #2
0
class Server(bottle.Bottle):

    def __init__(self):
        super(Server, self).__init__()
        self.chatbot = Chatbot('corpus.json')
        self.route('/', method='GET', callback=self.index)
        self.route('/chat', method='POST', callback=self.chat)
        self.route('/<path:path>', method='GET', callback=self.static)

    def index(self):
        return bottle.static_file('index.html', root='./')

    def static(self, path):
        return bottle.static_file(path, root='./')

    def chat(self):
        data = bottle.request.json
        response = self.chatbot.chat(data['text'])
        return json.dumps(response)
Example #3
0
 def test_app(self):
     USER_ID = "key1"
     chatbot = Chatbot()
     print(chatbot.chat(USER_ID, 'I love Pizza'))
     print(chatbot.chat(USER_ID, 'what do I like?'))
     print(chatbot.chat(USER_ID, 'whats my favorite food?'))
Example #4
0
def response_chat():
    chatbot = Chatbot()
    if request.method == 'POST':
        string = request.form["text"]
        response_string = chatbot.chat(string)
        return response_string