-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
31 lines (27 loc) · 750 Bytes
/
app.py
File metadata and controls
31 lines (27 loc) · 750 Bytes
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
from flask import (
Flask, request, redirect
)
from flask_cors import CORS
from models import ChatModel
import time
from config import *
app = Flask(__name__)
CORS(app)
kwchat = ChatModel()
answerTypes = ['dialog', 'drqa']
@app.route("/", methods=('GET', 'POST'))
def index():
if request.method == 'POST':
data = request.get_json()
question = data['msg']
start = time.time()
answer = kwchat.predict([question])
end = time.time()
answer = [item for (item,) in answer] # unpack
answer = {
'answerType': answerTypes[int(answer[1])],
'elapsedTime': end - start,
'msg': answer[0],
}
return answer
return redirect(webServerUrl)