Beispiel #1
0
def response(text, BOT, debugMode, reset, recent, name):
    if (debugMode == "trace" and reset == 'reset' and recent == 'recent'):
        fullresponse = API.debug_bot(USER_KEY,
                                     APP_ID,
                                     HOST,
                                     BOT,
                                     text,
                                     session_id=True,
                                     reset=True,
                                     trace=True,
                                     recent=True)
        print "Bot Response: ", fullresponse
    elif (debugMode == "trace" and reset == 'none'):
        fullresponse = API.debug_bot(USER_KEY,
                                     APP_ID,
                                     HOST,
                                     BOT,
                                     text,
                                     trace=True)
        print "Bot Response: ", fullresponse
    else:
        fullresponse = API.talk(USER_KEY,
                                APP_ID,
                                HOST,
                                BOT,
                                text,
                                clientID=name)
        bot_response = fullresponse['response']

        session_id = fullresponse['sessionid']
        print BOT + " says: \" ", bot_response, " \" "
        print "Session ID: " + str(session_id)
Beispiel #2
0
def bot_talk():
    """Respond to incoming texts with a text from your bot"""
    request_message = request.values.get('Body',  'twiliotest')
    bot_response = api.talk(user_key, app_id, host, botname, request_message)["response"]
    resp = twilio.twiml.Response()
    resp.message(bot_response)
    return str(resp)
Beispiel #3
0
def get_pb_response(seed_text):
	try:
		result = API.talk(user_key, app_id, host, botname, seed_text, session_id=True, recent=True)
		return result['response']
	except:
		result = "... I could be all wrong, but... "
		return result
def response(transcriptFile, pathForResponse):
    fileWrite = open(pathForResponse, 'w')
    with open(transcriptFile) as f:
        for line in f:
            response = API.talk(USER_KEY, APP_ID, HOST, BOT, line)
            bot_response = response['response']
            fileWrite.write(bot_response)
    fileWrite.close()
Beispiel #5
0
def message_bot(input):
    user_key = '99daf0495907c54b7e8fe16efbcfc7e7'
    app_id = '1409612772625'
    botname = 'testtechbot'
    input_text = input
    bot_session_id = '1'
    reply = API.talk(user_key, app_id, host, botname, input_text, bot_session_id, recent=True)
    return reply['response']
Beispiel #6
0
def bot_talk():
    """Respond to incoming texts with a text from your bot"""
    request_message = request.values.get('Body',  'twiliotest')
    bot_response = api.talk(user_key, app_id, host, botname, request_message)["response"]
    # resp = twilio.twiml.Response()

    client.send_message({'from': '+4552602330', 'to': '+4552602330', 'text': resp})
    
    resp.message(bot_response)
    return str(resp)
Beispiel #7
0
def talk(request):
    context_dict = {}

    if request.method == 'GET':
        session_id = 's1'
        message = request.GET.get('query')
        result = API.talk(settings.AI_KEY, settings.AI_ID, settings.AI_HOST, settings.AI_NAME, message, session_id, recent=True)
        context_dict['response'] = result['response']

    return JsonResponse(context_dict, safe=False)
def js_respond(response, bot_choice):
    if bot_choice == 0:
        bot_name = bot_list[0]
    elif bot_choice == 1:
        bot_name = bot_list[1]
    elif bot_choice == 2:
        bot_name = bot_list[2]
    result = API.talk(user_key, app_id, host, bot_name, response, recent=True)
    bot_response = result['response']
    return bot_response
def response(transcriptFile):
    with open(transcriptFile) as f:
        for line in f:
            response = API.talk(USER_KEY, APP_ID, HOST, BOT, line)
            bot_response = response['response']
            print "nao responds: ", bot_response
            #exclude = set(string.punctuation)
            #s = ''.join(ch for ch in bot_response if ch not in exclude)
            #lower_response = s.lower()
            #print "modified response: ", lower_response
    return bot_response
Beispiel #10
0
def get_pb_response(seed_text):
    try:
        result = API.talk(user_key,
                          app_id,
                          host,
                          botname,
                          seed_text,
                          session_id=True,
                          recent=True)
        return result['response']
    except:
        result = "... I could be all wrong, but... "
        return result
Beispiel #11
0
def showMain():
	'''Shows the main page'''
	if request.method == 'GET':
		global conversation
		conversation = []
		return render_template('main.html', conversation=conversation)
	if request.method == 'POST':
		error = ''
		question = request.form.get('question', '')
		if question and not question.isspace():
			response = pbApi.talk(user_key, app_id, host, botname, question)
			conversation.append((question, response['response']))
		else:
			error = 'Please enter a question'
		return render_template('main.html', conversation=conversation, error=error)
Beispiel #12
0
def get_bot_response():
	thread.start_new_thread(spinner, ())
	try:
		result = API.talk(user_key, app_id, host, botname, text1, session_id=True, recent=True)
	except:
		result = "... I could be all wrong... "
	pb_text2 = result['response']

	## When talking with pyggy only respond to the stem
	if userinput == 'bot':
		botresponse2 = bot.get_response(botresponse1)
	else:
		botresponse2 = bot.get_response(text1)

	text2 = pb_text2 + ' ' + botresponse2

	return text2
Beispiel #13
0
def showMain():
    '''Shows the main page'''
    if request.method == 'GET':
        return render_template('main.html',
                               conversation=conversation,
                               error=error)
    if request.method == 'POST':
        global error
        error = ''
        question = request.form.get('question', '')
        if question and not question.isspace():
            response = pbApi.talk(user_key, app_id, host, botname, question)
            answer = response['response'].replace('\n', '<br />')
            conversation.appendleft((question, answer))
        else:
            error = 'Please enter a question'
        return redirect('/')
def talk(input_text):
    global session_id

    result = API.talk(user_key,
                      app_id,
                      host,
                      botname,
                      input_text,
                      session_id,
                      recent=True)
    print result['response']

    # result = API.debug_bot(user_key, app_id, host, botname, input_text, session_id, reset=False, trace=True, recent=True)
    # print result['trace']

    if not session_id:
        session_id = result['sessionid']

    return result['response']
Beispiel #15
0
def get_bot_response():
    thread.start_new_thread(spinner, ())
    try:
        result = API.talk(user_key,
                          app_id,
                          host,
                          botname,
                          text1,
                          session_id=True,
                          recent=True)
    except:
        result = "... I could be all wrong... "
    pb_text2 = result['response']

    ## When talking with pyggy only respond to the stem
    if userinput == 'bot':
        botresponse2 = bot.get_response(botresponse1)
    else:
        botresponse2 = bot.get_response(text1)

    text2 = pb_text2 + ' ' + botresponse2

    return text2
Beispiel #16
0
def communicator():
    """Respond and greet the caller by name."""

    # Retrieved information from SMS Twilio
    from_number = request.values.get('From', None)
    message_body = request.values.get('Body', "")
    date_created = request.values.get('DateCreated', "")
    account_sid = request.values.get('AccountSid', "")
    date_created = request.values.get('DateCreated', "")


    if from_number in callers:
        message = callers[from_number] + ", thanks for the message:" + message_body + "!"
    else:
        message = "Buddy, thanks for the message!" + message_body


    message = talk(message_body)
    bot_response = api.talk('2a2a1569fe48655c89487a7e8c6cb214', '1409612442334', 'http://aiaas.pandorabots.com', 'alok', message_body)["response"]

    resp = twilio.twiml.Response()
    resp.message(bot_response)

    return str(resp)
Beispiel #17
0
# r = sr.Recognizer()

timenow = time.time()
with open('logs/' + str(timenow) + '_log.csv', 'wb') as csvfile:
		writer = csv.writer(csvfile)
		fieldnames = ['timestamp', 'input_text', 'response']
		writer.writerow(fieldnames)
		text1 = "Good Morning"
		# text1 = "What is your name?"
		
		while True:
			# Fiona says something (chatterbot)
			speak_response(text1, 'Fiona')

			# Pyggy responds (pandorabot)
			result = API.talk(user_key, app_id, host, botname, text1, session_id=True, recent=True)
			text2 = result['response']
			
			# time.sleep(0.1)
			speak_response(text2, 'Rosie')

			# Save the back and forth to the CSV log
			writer.writerow([time.time(),text1,text2])
			csvfile.flush()

			# Fiona updates what to say next (random choice of bot seed)
			coin = random.random()
			highLim = 0.99
			lowLim = 0.01

			if coin > highLim:
Beispiel #18
0
def query_bot(text, screen_name, cust_id):
    #remove any '@usernames' from tweet
    user_input = re.sub('@[a-zA-Z0-9_]{1,15}','',text).strip()
    output = pandorabots_api.talk(user_key, app_id, host, botname, user_input, clientID = cust_id)["response"]
    return output
# Bot creation
# result = API.create_bot(user_key, app_id, host, botname)
# print(result)

# Bot listing
result = API.list_bots(user_key, app_id, host)
print result

# Files such as AIML uploading
# for files in full_file_paths:
#     print files
#     result = API.upload_file(user_key, app_id, host, botname, files)
#     print result

# List files
result = API.list_files(user_key, app_id, host, botname)

# Retrieve files
# filename = 'udc.aiml'
# result = API.get_file(user_key, app_id, host, botname, filename)
# print result

# Bot Compilation
result = API.compile_bot(user_key, app_id, host, botname)

# Send input to Bot
result = API.talk(user_key, app_id, host, botname, input)

bot_response = result['response']
session_id = result['sessionid']
print bot_response
Beispiel #20
0
def query_bot(text, screen_name, cust_id):
    # remove any '@usernames' from tweet
    user_input = re.sub("@[a-zA-Z0-9_]{1,15}", "", text).strip()
    output = pandorabots_api.talk(user_key, app_id, host, botname, user_input, clientID=cust_id)["response"]
    return output
Beispiel #21
0
short_sonnet = ngram.generate_text(lm, 12, nletters=200)

timenow = time.time()
with open('logs/' + str(timenow) + '_log.csv', 'wb') as csvfile:
    with sr.Microphone() as source:
        r.adjust_for_ambient_noise(source)
        writer = csv.writer(csvfile)
        fieldnames = ['timestamp', 'input_text', 'response']
        writer.writerow(fieldnames)
        opener = "Let's start with your name..."
        speak_response(opener)
        while True:
            audio = r.listen(source)
            try:
                input_text = r.recognize_google(audio)
                print("You said: " + input_text)
                result = API.talk(user_key,
                                  app_id,
                                  host,
                                  botname,
                                  input_text,
                                  session_id=True,
                                  recent=True)
                response = result['response']
                writer.writerow([time.time(), input_text, response])
                csvfile.flush()
                speak_response(response)
                # time.sleep(0.1)
            except:
                pass