Beispiel #1
0
    def _insert_message(self, msg, sender):
        if not msg:
            return
        
        if msg == "exit" or msg == "goodbye":
            self.window.destroy()
        
        else:
            self.text_widget.tag_config("you", background="#5CE5D5", font=("AdHoc 13"))
            self.text_widget.tag_config("chatbot", background="#7898FB", font=("AdHoc 13"))

            self.msg_entry.delete(0, END)
            msg1_sender = f"{sender}:"
            msg1_msg = f" {msg}\n"
            self.text_widget.configure(state=NORMAL)
            self.text_widget.insert(END, msg1_sender, "you")
            self.text_widget.insert(END, msg1_msg)
            self.text_widget.configure(state=DISABLED)

            msg2_bot = f"{bot_name}:"
            msg2, _ = get_response(msg)
            msg2_msg = f" {msg2}\n\n"
            self.text_widget.configure(state=NORMAL)
            self.text_widget.insert(END, msg2_bot, "chatbot")
            self.text_widget.insert(END, msg2_msg)
            self.text_widget.configure(state=DISABLED)

            self.text_widget.see(END)
Beispiel #2
0
def index():
    if request.method == 'POST':
        message = request.form['content']
        reponse = get_response(message)
        with open(filename) as json_file:
            msg = json.load(json_file)

            temp = msg['Chat']
            # python object to be appended
            y = {"message-user": message, "reponse": reponse}
            # appending msg to emp_details
            temp.append(y)

        write_json(msg)

        return render_template('index.html',
                               monBot=bot_name,
                               reponse=reponse,
                               message=message)

    else:
        return render_template('index.html')
Beispiel #3
0
def VoiceChat():
    print(greeting)
    while True:
        with sr.Microphone() as source:
            try:
                print(you, end="")
                r.adjust_for_ambient_noise(source, duration=0.2)
                audio = r.listen(source)
                sentence = r.recognize_google(audio)
                print(sentence)

                if sentence == "goodbye" or sentence == "exit":
                    response = "Thank you for visiting! I hope to see you again!"
                    print(f'{bot_name}: {response}\n')
                    TextToSpeech(response)
                    break

                response = get_response(sentence)
                print(f'{bot_name}: {response}\n')
                TextToSpeech(response)

            except Exception as e:
                print(e)
Beispiel #4
0
def predict():
    text=request.get_json().get("message")
    response=get_response(text)
    message={"answer": response}
    return jsonify(message)
Beispiel #5
0
def predict():
    text = request.get_json().get("message")
    #todo check if text is valid
    response = get_response(text)
    message = {"answer": response}
    return jsonify(message)
Beispiel #6
0
 def handleMessage(self):
     # echo message back to client
     message = self.data
     response = get_response(message)
     self.sendMessage(response)
Beispiel #7
0
if __name__ == "__main__":
    if args.gui:
        from gui import ChatApplication
        app = ChatApplication()
        app.run()

    if args.cli:
        from chat import bot_name, get_response
        from common import *
        print(greeting)

        while True:
            print(you, end="")
            sentence = input()
            if sentence == "exit" or sentence == "goodbye":
                print(
                    f'{bot_name}: Thank you for visiting! I hope to see you again!\n'
                )
                break

            response, _ = get_response(sentence)
            print(f'{bot_name}: {response}\n')

    if args.voice:
        from voice import VoiceChat
        VoiceChat()

    if args.train:
        from train import trainModel
        trainModel(args.train)
Beispiel #8
0
questions = {
    "how are you doing today?": "about",
    "configure laptop steps": "configuration",
    "what time do you guys close?": "opening_time",
    "what is affecting sales?": "factors_impacting_sale",
    "I don't understand what your product does": "solve_problems",
    "I don't remember my password": "******",
    "please tell my list of appointments": "appointment_status",
    "can I have an appointment with your manager?": "appointment_book",
    "THANK YOU SO MUCH": "thanks",
    "what information do your supplier know?": "supplier_info",
    "who is your manufacturer": "manufacturing_problems",
    "what do your customers say?": "customer_satisfaction",
    "what do you have in stock?": "gadgets",
    "where is your shop located?": "store_location",
    "tell me what ratings your customers give you": "customer_satisfaction"
}

from chat import get_response
from prettytable import PrettyTable

t = PrettyTable(["Question", "Actual Tag", "Predicted Tag", "Match Tag"])

for question in questions:
    _, tag = get_response(question)
    t.add_row([question, questions[question], tag, tag == questions[question]])

print(t)