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)
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
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 )
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)
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')
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
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))
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")
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')
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
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'))
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)
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.."
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)
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('<', "<").replace('>', ">") 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('<', "<").replace('>', ">") userText = '<div class="outgoing" id="jes"> <span class="msg2">{}</span> </div>'.format( user_text) return userText
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"
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.")
def start_server(): cb.chat() hs.run()
def chat(): chatbot.chat()
def get_bot_response(): userText = request.args.get('msg') return str(chat(userText))
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)
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)
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)
def func(): text = request.form['in'] return render_template('portal.html', text=chat(text))
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)
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)
def echo_all(message): answear = chatbot.chat(message.text) bot.reply_to(message, answear)