-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
86 lines (54 loc) · 1.49 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# -*- coding: utf-8 -*-
from flask import Flask
from flask import render_template,request, jsonify
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
#from chatterbot import ChatBot
import chatbot
#import trainer
import os
from json import dumps
app = Flask(__name__)
chatbot.train()
@app.route("/test")
def main():
return "test complete!"
@app.route("/speech", methods = ['POST'])
def handleSpeech():
json = request.json
text = json.get('speech')
isUser = json.get('isUser')
#print(p);
if isUser == "true":
print "user response: " + text
#trainer.main(text)
return jsonify({})
else:
print "friend said: " + text
# Get a response to the input text
response = chatbot.getResponse(text)
#trainer.raw_text = response
#execfile("trainer.py")
# LSTM.raw_text = text // LSTM.main()<< could do this to use the neural net in the future
recc = response.serialize()
print "reccomend: " + recc['text']
return jsonify({'recc': recc['text']})
'''
def set_interval(func,sec):
print 'start interval'
def wrapper_func():
set_interval(func, sec)
func()
t = threading.Timer(sec, wrapper_func)
t.start()
return t
def keep_app_alive():
requests.get('http://tipofthetongue.herokuapp.com/')
'''
if __name__ == '__main__':
port = int(os.environ.get("PORT", 5000))
http_server = HTTPServer(WSGIContainer(app))
print "listening on port " + str(port)
http_server.listen(port)
IOLoop.instance().start()