-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
47 lines (42 loc) · 1.81 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
from flask import Flask, request
from flask_cors import CORS
import requests
from ChitChatHandler import ChitChatHandler
from RedditDataHandler import RedditDataHandler
from RasaHandler import RasaHandler
import urllib.parse as urllib3
app = Flask(__name__)
CORS(app)
@app.route('/getresponse', methods=['GET'])
def search():
args = request.args
query = args.get("query", default="", type=str)
core = args.get("core", default="default", type=str)
searchPolitics = args.get("politics", default=0, type=int)
searchEnvironment = args.get("environment", default=0, type=int)
searchTechnology = args.get("technology", default=0, type=int)
searchHealthcare = args.get("healthcare", default=0, type=int)
searchEducation = args.get("education", default=0, type=int)
searchAll = args.get("all", default=0, type=int)
finalResponse = 'Sorry, I do not have an answer to this question. I will learn soon hopefully.'
rasaResponse = rasa.getRasaResponse(query)
if rasaResponse!= None:
return rasaResponse
if(cc.isChitChat(query)):
chitChatResponse = cc.getChitChatResponse(query)
if chitChatResponse == None:
response = reddit.getResponse(query,core,searchPolitics,searchEnvironment,searchTechnology,searchHealthcare,searchEducation,searchAll)
if response != None:
finalResponse = response
else:
finalResponse = chitChatResponse
else:
response = reddit.getResponse(query,core,searchPolitics,searchEnvironment,searchTechnology,searchHealthcare,searchEducation,searchAll)
if response != None:
finalResponse = response
return finalResponse
if __name__ == "__main__":
cc = ChitChatHandler()
reddit = RedditDataHandler()
rasa = RasaHandler()
app.run(host="0.0.0.0", port=9999)