Ejemplo n.º 1
0
    def get_response(self):
        global correctNameGiven
        global count
        """ get response from textbox"""
        user_input = self.usr_input.get()
        self.usr_input.delete(0, tk.END)
        """ get response from mic"""
        #user_input = chatbot.getAudio()
        #print("0")
        """ get response from chatbot """
        output = chatbot.chat(user_input, correctNameGiven)
        """
        To check whether user has given his name
        """
        if (output == -1):
            count += 1
            if (count < 3):
                output = 'Invalid name\nTell me your name please...!!!'
            else:
                output = 'I will not talk further until you will not give your correct name..!!'
        else:
            correctNameGiven = True

        #print("1")
        self.conversation['state'] = 'normal'
        """ show oputput """
        self.conversation.insert(
            tk.END,
            "Human: " + user_input + "\n" + "ChatBot: " + output + "\n")
        self.conversation['state'] = 'disabled'

        time.sleep(0.5)
Ejemplo n.º 2
0
def chat():

    while True:
        print("Contexto antigo: " + str(glob.context))
        print("Contexto novo: " + str(glob.new_context))

        if glob.context != glob.new_context:
            glob.context = glob.new_context
            glob.words, glob.labels, glob.training, glob.output, glob.model, glob.data = load_model(
                glob.context, glob.lang)

        inp = chatbot.get_audio()
        chatbot.chat(inp)

        if glob.new_context == "goodbye":
            break
Ejemplo n.º 3
0
def handle_my_custom_event1( json1 ):
  import chatbot
  message = json1['message']
  answer=chatbot.chat(message)
  json1['answer'] = answer
  json1['bot']='J.A.R.V.I.S'
  print( 'recived my event: ' + str(json1 ))
  socketio.emit( 'my response', json1, callback=messageRecived )
Ejemplo n.º 4
0
def get_bot_response():
    user_input = request.args.get('msg')
    bot_response = chatbot.chat(user_input)
    #bot_response = "hello"

    print(user_input)
    print(bot_response)
    return str(bot_response)
Ejemplo n.º 5
0
def present_and_clear(event='<Return>'):
    out = "You: " + msg.get()
    text.insert(END, "\n" + out)
    if msg.get().lower() == "quit":
        root.destroy()
    else:
        text.insert(END, "\n" + "Justin: " + chat(msg.get()))
        text.see(END)
        msg.delete(0, 'end')
Ejemplo n.º 6
0
def incoming_sms():
    """Send a dynamic reply to an incoming text message"""
    global companies
    message_limit = 500  # To prevent sending the user a barrage of messages

    # Get the message the user sent our Twilio number
    body = request.values.get('Body', None)

    # Start our TwiML response
    resp = MessagingResponse()

    # Determine the right reply for this message
    try:
        # Welcome Message
        if body == 'Wage Theft':
            resp.message(
                "Thanks for using our service. Please enter the name of the company you're interested in"
            )
        elif body.isdigit():
            body = int(body)

            # User has entered the number of the company from the list
            if body < 10000 and companies:
                company = companies[body - 1]
                msg = chatbot.final_response(company)
                resp.message(msg)

            # User has entered a zipcode
            elif body >= 10000:
                companies = chatbot.search_by_zip(companies, body)
                addresses = chatbot.all_addresses(companies)
                msg = str(chatbot.format_addresses(addresses))
                if len(msg) <= message_limit:
                    resp.message(msg)
                else:
                    resp.message(
                        f"There are a lot of results for {body}. Please enter the zip code of the company."
                    )
            else:
                resp.message(
                    "Please enter the name of the company you're interested in"
                )
        else:
            companies = chatbot.chat(body)
            addresses = chatbot.all_addresses(companies)
            msg = str(chatbot.format_addresses(addresses))
            if len(msg) <= message_limit:
                resp.message(msg)
            else:
                resp.message(
                    f"There are a lot of results for {body}. Please enter the zip code of the company."
                )
    except:
        resp.message("Sorry, we didn't quite get that. Please say that again")

    return str(resp)  # Output to the webhook - doesn't get sent to user
Ejemplo n.º 7
0
def process_text_message(event):
    replyJsonPath = event.message.text
    if detect_from_follower(replyJsonPath):
        message_array = detect_from_follower(replyJsonPath)
        line_bot_api.reply_message(event.reply_token, message_array)
    else:
        message_array = chat(replyJsonPath)
        print(message_array)
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(message_array))
Ejemplo n.º 8
0
 def test_tag(self):
     chatbot.chat("How are you")
     self.assertEqual(chatbot.tag, "greeting")
     chatbot.chat("see you later")
     self.assertEqual(chatbot.tag, "goodbye")
     chatbot.chat("how old")
     self.assertEqual(chatbot.tag, "age")
Ejemplo n.º 9
0
def present_and_clear(event='<Return>'):
    global inFrench
    out = "You: " + msg.get()
    text.insert(END, "\n" + out)
    if msg.get().lower() == "quit":
        root.destroy()
    elif "definition" in msg.get():
        if inFrench:
            text.insert(
                END, "\n" + "Justin: " +
                myTranslator(myWikipedia(msg.get().split("of")[1])))
            text.see(END)
            msg.delete(0, 'end')
        else:
            text.insert(
                END, "\n" + "Justin: " + myWikipedia(msg.get().split("of")[1]))
            text.see(END)
            msg.delete(0, 'end')
    elif msg.get() == "in french":
        inFrench = True
        text.insert(END, "\n" + "Justin: " + "I will now speak in French")
        text.see(END)
        msg.delete(0, 'end')
    elif msg.get() == "in english":
        inFrench = False
        text.insert(
            END,
            "\n" + "Justin: " + myTranslator("I will now speak in English"))
        text.see(END)
        msg.delete(0, 'end')
    else:
        if inFrench:
            text.insert(END, "\n" + "Justin: " + myTranslator(chat(msg.get())))
            text.see(END)
            msg.delete(0, 'end')
        else:
            text.insert(END, "\n" + "Justin: " + chat(msg.get()))
            text.see(END)
            msg.delete(0, 'end')
Ejemplo n.º 10
0
def messageHandler(Update):
    global lastMessageId
    text = getText(Update)
    msg_id = getMessageId(Update)
    user_id = getUserId(Update)
    lastMessageId = msg_id
    msg_id = getMessageId(Update)
    #if lastMessageId != msg_id:
    #if text == '/stop': # Button function add by Bot-father
    #    break
    #  else:
    reply_text = chatbot.chat(text, model, vdict)
    BOT.sendMessage(user_id, reply_text)
    print('> send from ', msg_id, ':', text)
    print('> send to ', msg_id, ':', reply_text)
    # add logging to txt
    return
Ejemplo n.º 11
0
def listen():
	global allow_speak
	new_msg = voice_rec()
	new_msg_obj= Message(msg=new_msg,sender=session['id'],receiver=0,user=session['id'])
	db.session.add(new_msg_obj)
	db.session.commit()
	bot_msg=''
	if 'time' in new_msg or 'date' in new_msg:
		bot_msg=str(now.hour) +":"+str(now.minute)
	else:
		bot_msg=str(chat(new_msg))
		if check_str(bot_msg) != 'nu':
			return redirect(check_str(bot_msg))
	allow_speak =True
	new_msg_obj= Message(msg=bot_msg,sender=0,receiver=session['id'],user=session['id'])
	db.session.add(new_msg_obj)
	db.session.commit()
	#speak() 
	return redirect(url_for('home'))
Ejemplo n.º 12
0
    def send_message_insert(self, message):

        user_input = self.entry_field.get()
        pr1 = "You : " + user_input + "\n"

        self.text_box.configure(state=NORMAL)
        self.text_box.insert(END, pr1)
        self.text_box.configure(state=DISABLED)
        self.text_box.see(END)

        response = chat(user_input)
        pr = "Bot : " + response + "\n"

        self.text_box.configure(state=NORMAL)
        self.text_box.insert(END, pr)
        self.text_box.configure(state=DISABLED)
        self.text_box.see(END)
        self.last_sent_label(
            str(
                time.strftime("Last message sent: " + '%B %d, %Y' + ' at ' +
                              '%I:%M %p')))
        self.entry_field.delete(0, END)
Ejemplo n.º 13
0
def user_msg(jsdata):
    msg, tag = chat(jsdata)
    # print(msg+tag)
    if tag in ["greeting", "goodbye", "name", "hours"]:
        STATE = "chatbot"
        if tag == "greeting":
            msg += "<br>I can tell you about some facts/myths or about this pandemic."
        return msg
    elif tag == "corona":
        STATE = "corona_chatbot"
        return msg
        # for x in jsdata.lower().split():
        # 	if x in ["pandemic","covid-19","corona","coronavirus","virus"]:
        # 		print(msg)
        # 		return "First tell me the what you want to know about, <br> 1.) Total Cases 2.) Total Deaths 3.) Total Recovered cases"
        # 	elif x in ["cases","deaths","recovered","1","2","3"]:
        # 		STATE = "corona_chatbot"
        # 		print(msg)
        # 		return "Tell me the country name now"
    elif tag == "facts":
        return msg
    elif tag == "none":
        return "Umm, I didn't get you.."
Ejemplo n.º 14
0
def home():
    #bot-chat function
	global allow_speak
	if session.get('logged_in'):
	   if allow_speak == True:
		   speak() 
		   allow_speak =False
	   #if request.method == 'POST' :
		   #print(voice_rec())

	   if request.method == 'POST':
		   new_msg = request.form.get('message')
		   
		   
		   print(new_msg)
		   new_msg_obj= Message(msg=new_msg,sender=session['id'],receiver=0,user=session['id'])
		   db.session.add(new_msg_obj)
		   db.session.commit()
		   if 'time' in new_msg or 'date' in new_msg:
			   bot_msg = str(now.hour) +":"+ str(now.minute)
		   else:
			   bot_msg=str(chat(new_msg))
			   if check_str(bot_msg) != 'nu':
				   return redirect(check_str(bot_msg))
		   allow_speak = True

           #####
		   new_msg_obj= Message(msg=bot_msg,sender=0,receiver=session['id'],user=session['id'])
		   db.session.add(new_msg_obj)
		   db.session.commit()
		   #Messages.query.filter_by(sender=session['id'])
		   return redirect('/#')   
	if not session.get('logged_in'):
		return redirect(url_for('login'))
	else:
		return render_template('index.html',msgs=Message.query.filter_by(user=session['id']).all()[-5:], func=speak)
	return render_template('index.html',msgs=Message.query.filter_by(user=session['id']).all()[-5:], func=speak)
Ejemplo n.º 15
0
def getrespont():
    if request.method == "GET":  #better POST ?
        if "ID" in session:
            uniqe_session_id = session["ID"]
            if database.AI(uniqe_session_id):
                user_text = str(request.args.get('search'))
                user_text = user_text.replace('<',
                                              "&lt;").replace('>', "&gt;")
                bot_responce = chatbot.chat(user_text)
                database.insert_chat(uniqe_session_id, "A", user_text)
                database.insert_chat(uniqe_session_id, "R", bot_responce)
                userText = '<div class="outgoing" id="jes"> <span class="msg2">{}</span> </div>'.format(
                    user_text)
                output = '<div class="incomming" id="jes"> <span class="msg1">{}</span> </div>'.format(
                    bot_responce)
                output = userText + output
                return output
            else:
                user_text = str(request.args.get('search'))
                user_text = user_text.replace('<',
                                              "&lt;").replace('>', "&gt;")
                userText = '<div class="outgoing" id="jes"> <span class="msg2">{}</span> </div>'.format(
                    user_text)
                return userText
Ejemplo n.º 16
0
    def display(self):

        mytextinput = self.root.ids.my_textinput
        user_input = mytextinput.text
        mylabel = self.root.ids.my_label
        mytextinput.text = ""

        global correctNameGiven
        global count
        """ get response from chatbot """
        output = chatbot.chat(user_input, correctNameGiven)
        """
        To check whether user has given his name
        """
        if (output == -1):
            count += 1
            if (count < 3):
                output = Strings.invalidName
            else:
                output = Strings.notTalkFurther
        else:
            correctNameGiven = True

        mylabel.text += Strings.you + user_input + "\n" + Strings.emmaTag + output + "\n\n"
Ejemplo n.º 17
0
 def test_sentiment(self):
     self.assertEqual(chatbot.chat("I love your work"),
                      "Glad to hear you really like that.")
     self.assertEqual(chatbot.chat("I hate you"), "I can understand that.")
     self.assertEqual(chatbot.chat("I like this conversation"),
                      "I fully agree.")
Ejemplo n.º 18
0
def start_server():
    cb.chat()
    hs.run()
Ejemplo n.º 19
0
def chat():
    chatbot.chat()
Ejemplo n.º 20
0
def get_bot_response():
    userText = request.args.get('msg')
    return str(chat(userText))
Ejemplo n.º 21
0
 def test_failResponses(self):
     self.assertTrue(chatbot.chat("Who is Gahlran?") in chatbot.others)
     self.assertTrue(
         chatbot.chat("do you play among us?") in chatbot.others)
Ejemplo n.º 22
0
 def test_synonyms(self):
     self.assertTrue(
         chatbot.chat("what type of music do you listen to") in
         self.responsesmusic)
     self.assertTrue(
         chatbot.chat("what tunes do you listen to") in self.responsesmusic)
Ejemplo n.º 23
0
 def test_punctuation(self):
     self.assertTrue(chatbot.chat("how are you.") in self.responses)
     self.assertTrue(chatbot.chat("how are you!") in self.responses)
     self.assertTrue(chatbot.chat("how are you?") in self.responses)
Ejemplo n.º 24
0
def func():
    text = request.form['in']

    return render_template('portal.html', text=chat(text))
Ejemplo n.º 25
0
 def test_chat(self):
     self.assertTrue(chatbot.chat("How are you") in self.responses)
     self.assertTrue(chatbot.chat("Is anyone there?") in self.responses)
     self.assertTrue(chatbot.chat("hello") in self.responses)
     self.assertTrue(chatbot.chat("good day") in self.responses)
     self.assertTrue(chatbot.chat("whats up?") in self.responses)
Ejemplo n.º 26
0
 def test_capitalization(self):
     self.assertTrue(chatbot.chat("hOW aRE yOU") in self.responses)
     self.assertTrue(chatbot.chat("HOW ARE YOU") in self.responses)
     self.assertTrue(chatbot.chat("how are you") in self.responses)
Ejemplo n.º 27
0
def echo_all(message):
    answear = chatbot.chat(message.text)
    bot.reply_to(message, answear)