""" Train retrieval-based chatbot on xiaohuangji subtitle dataset. Use python 3 """ import os import sys sys.path.append(os.getcwd()) sys.path.append(os.getcwd() + '/chatbot') sys.path.append(os.getcwd() + '/chatbot/corpus') args_in = '--device gpu0 ' \ '--test daemon ' \ '--modelTag xiaohuangji_2l_lr002_dr09_emb256_len20_vocab8000 ' \ '--vocabularySize 8000 --maxLength 20 ' \ '--learningRate 0.002 --dropout 0.9 ' \ '--rootDir /Users/xushuang/sf/chatbot/DeepQA/ ' \ '--saveEvery 500 ' \ '--corpus xiaohuangji '.split() # --datasetTag wechat ' \ from chatbot import chatbot print(args_in) chatbot = chatbot.Chatbot() chatbot.main(args_in) print(chatbot.daemonPredict("工作"))
def setUp(self): self.chatbot = chatbot.Chatbot()
def __init__(self): bot = chatbot.Chatbot()
def get_negative_timeline(): telco = request.args.get("telco") data = t_sentis.get_negative_count(telco) return jsonify(data) @app.route("/totalTweets",methods=["GET"]) def get_total_tweets(): telco = request.args.get("telco") data = t_graph.get_total_tweets(telco) return jsonify(data) if __name__ == "__main__": #Init all the ML Models app.config["DATA"] = os.path.join(app.root_path, 'data', 'DATA.csv') app.config["M1"] = os.path.join(app.root_path, 'data', 'm1.csv') app.config["STARHUB"] = os.path.join(app.root_path, 'data', 'starhub.csv') app.config["GREV"] = os.path.join(app.root_path, 'data', 'GREV.json') app.config["GREVS"] = os.path.join(app.root_path, 'data', 'GREVS.json') app.config["GREVM"] = os.path.join(app.root_path, 'data', 'GREVM.json') global chat_bot, t_graph, t_tweets, t_sentis, t_grev chat_bot = chatbot.Chatbot(app) t_graph = graphs.Graphs(app) t_tweets = tweets.Tweets(app) t_sentis = sentiments.Sentiments(app) t_grev = grev.Greviance(app) #Have a config file for ports and static stuff app.run()
def get_chatbot(self): cbot = chatbot.Chatbot() cbot.initResponseCall() return cbot
import os from flask import Flask, request, send_file, send_from_directory, session from werkzeug import secure_filename # belows include self-define libs and func from AWWW_wav_to_spectro import wav2sep from AWWW_wav_to_STT import input_filename from AWWW_jiebaCut import func_cut from AWWW_chatbot_response import Chat_with_Bot from AWWW_pic_pred import pred # aboves include self-define libs and func import numpy as np import json from chatbot import chatbot AkishinoProjectBot = chatbot.Chatbot() AkishinoProjectBot.main([ '--modelTag', 'taiwa20170709', '--test', 'daemon', '--initEmbeddings', '--embeddingSource=wiki.zh.bin' ]) app = Flask(__name__) app.config['UPLOAD_FOLDER'] = 'uploads/' app.config['ALLOWED_EXTENSIONS'] = set(['wave', 'wav']) def allowed_file(filename): return '.' in filename and \ filename.rsplit('.', 1)[1] in app.config['ALLOWED_EXTENSIONS']
def __init__(self): # instantiate QA Chatbot self.chat = chatbot.Chatbot() self.chat.telecomChatBotSessionOpen()
def main(): client = vkl.Client() while not client.authorization(): continue client.save_full_message_history() cb = chatbot.Chatbot() cb.main() print(__info__) url = client.make_url() c = pycurl.Curl() m = pycurl.CurlMulti() last_rnd_id = 1 reply_count = 0 while True: s = BytesIO() c.setopt(c.URL, url) c.setopt(c.WRITEFUNCTION, s.write) m.add_handle(c) while True: ret, num_handles = m.perform() if ret != pycurl.E_CALL_MULTI_PERFORM: break while num_handles: # main loop animate_loading( 'Listening long poll... {} {ans}'.format( reply_count, ans = 'answer' if reply_count == 1 else 'answers' ), 1 ) while 1: # main loop (2) ret, num_handles = m.perform() if ret != pycurl.E_CALL_MULTI_PERFORM: break m.remove_handle(c) response = s.getvalue() response = response.decode('utf-8') response = json.loads(response) url = client.make_url(keep_ts=response['ts']) for update in response['updates']: if update[0] == 4 and\ update[7] !=\ last_rnd_id and\ update[6] != '': # response == message # message != last_message # message != '' text = update[6] mark_msg = True if re.sub('^( )*', '', text).startswith('/'): text = text[1:] if text.startswith('/'): mark_msg = False text = text[1:] text = parse_input(text, replace_vkurl=False, replace_nl=False) words = text.split() if not words: words = ' ' if re.match('^((help)|(помощь)|(info)|(инфо)|(информация)|\?)',\ words[0].lower()): text = __info__ elif re.match('^((скажи)|(say))', words[0].lower()): del words[0] text = ' '.join(words) else: text = re.sub('(__nm__)|(__nl__)', '\n', cb.daemonPredict(text)) else: continue last_rnd_id = update[7] + 1 client.reply( uid = update[3], text = text + "'" if mark_msg else text, rnd_id = last_rnd_id ) reply_count += 1
def index(): if request.method == 'POST': file = request.files['file'] if file and allowed_file(file.filename): # print(file) filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) # return redirect(url_for('uploaded_file',filename = filename)) """wav2sep(filename) ans = pred() # below decode json from nvidia digits output jsondec = json.loads(ans.decode('utf8')) jsondec = jsondec['predictions'] jsondec = str(jsondec).replace("[", "") jsondec = str(jsondec).replace("]", "") jsondec = "{" + jsondec + "}" jsondec = jsondec.replace("',", "':") jsondec = jsondec.replace("'", '"') jsondec = json.loads(jsondec) respred = ((jsondec['happy'], jsondec['sad'], jsondec['calm'], jsondec['fearful'], jsondec['angry'])) maxpred = (max(jsondec['happy'], jsondec['sad'], jsondec['calm'], jsondec['fearful'], jsondec['angry'])) if maxpred == jsondec['happy']: print("開心 : " + str(jsondec['happy'])) elif maxpred == jsondec['sad']: print("傷心 : " + str(jsondec['sad'])) elif maxpred == jsondec['calm']: print("平靜 : " + str(jsondec['calm'])) elif maxpred == jsondec['fearful']: print("害怕 : " + str(jsondec['fearful'])) elif maxpred == jsondec['angry']: print("生氣 : " + str(jsondec['angry'])) else: print("無法辨識")""" from chatbot import chatbot AkishinoProjectBot = chatbot.Chatbot() """if maxpred == (jsondec['happy']): AkishinoProjectBot.main(['--modelTag', 'positive_negative_correct', '--test', 'daemon']) elif maxpred == jsondec['sad']: AkishinoProjectBot.main(['--modelTag', 'positive_negative_correct', '--test', 'daemon']) elif maxpred == jsondec['calm']: AkishinoProjectBot.main(['--modelTag', 'positive_negative_correct', '--test', 'daemon']) elif maxpred == jsondec['fearful']: AkishinoProjectBot.main(['--modelTag', 'positive_negative_correct', '--test', 'daemon']) elif maxpred == jsondec['angry']: AkishinoProjectBot.main(['--modelTag', 'positive_negative_correct', '--test', 'daemon']) else: print("無法辨識")""" AkishinoProjectBot.main( ['--modelTag', 'model-AIA', '--test', 'daemon']) asking = str(input_filename(filename)) print("asking = " + asking) if asking == "None": #responsing = Chat_with_Bot(asking, AkishinoProjectBot) asking = "無法辨識" print("chatbot_responsing asking = " + asking) else: asking = func_cut(input_filename(filename)) responsing = Chat_with_Bot(asking, AkishinoProjectBot) print("chatbot_responsing asking_res = " + responsing) if responsing == "": responsing = "無法回應" print("responsing = " + responsing) #asking = str(input_filename(filename)) print("asking = " + asking) #ans_del = pred_del(filename) json_res = [{'1_ask': asking, '2_response': responsing}] #print("maxpred = " + str(maxpred[0])) #shutdown web server shutdown() #print(ans.decode('utf8').replace("\n"," ")) #return str(maxpred[0]) #reload = restart() return jsonify(json_res) #return (ans.decode('utf8') + "|" +"ask = "+ asking_res + "," + "response = "+ responsing) return ("ask = " + asking + "," + "response = " + responsing) return '''
def compute(): question = request.form['input_message'] chat = chatbot.Chatbot() chat.main() answer = chat.mainTestInteractive(message=question) return
def init(): bot = chatbot.Chatbot() bot.main(args_in) return bot
def __init__(self, model_tag, chatbot_path): self.bot = chatbot.Chatbot() self.bot.main([ '--modelTag', model_tag, '--test', 'daemon', '--rootDir', chatbot_path, '--keepAll' ])
def __init__(self, model_path): self._model = chatbot.Chatbot(model_path) self._model.start([]) self._response = "I didn't understand your question ?"