-
Notifications
You must be signed in to change notification settings - Fork 38
/
app.py
44 lines (36 loc) · 1.42 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
# Ref: https://github.com/bhavaniravi/rasa-site-bot
from flask import Flask
from flask import render_template,jsonify,request
import requests
# from models import *
from engine import *
import random
app = Flask(__name__)
app.secret_key = '12345'
@app.route('/')
def hello_world():
return render_template('home.html')
get_random_response = lambda intent:random.choice(intent_response_dict[intent])
@app.route('/chat',methods=["POST"])
def chat():
try:
user_message = request.form["text"]
response = requests.get("http://localhost:5000/parse",params={"q":user_message})
response = response.json()
entities = response.get("entities")
topresponse = response["topScoringIntent"]
intent = topresponse.get("intent")
print("Intent {}, Entities {}".format(intent,entities))
if intent == "gst-info":
response_text = gst_info(entities)# "Sorry will get answer soon" #get_event(entities["day"],entities["time"],entities["place"])
elif intent == "gst-query":
response_text = gst_query(entities)
else:
response_text = get_random_response(intent)
return jsonify({"status":"success","response":response_text})
except Exception as e:
print(e)
return jsonify({"status":"success","response":"Sorry I am not trained to do that yet..."})
app.config["DEBUG"] = True
if __name__ == "__main__":
app.run(port=8080)