-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
50 lines (32 loc) · 1.09 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
import logging
import azure.functions as func
import os
#os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
from allennlp.predictors.predictor import Predictor
import json
logging.info('Starting General Bots Models server.')
# https://ai.google.com/research/NaturalQuestions
predictor = None
from flask import Flask, render_template, request
import hmac
app = Flask(__name__)
@app.route("/reading-comprehension", methods=['POST'])
def index():
logging.info('General Bots QA.')
content = request.form.get('content')
question = request.args.get('question')
key = request.args.get('key')
if not hmac.compare_digest(key, 'starter'):
return 'Invalid key.'
global predictor
if predictor is None:
predictor = Predictor.from_path("https://storage.googleapis.com/allennlp-public-models/transformer-qa-2020-10-03.tar.gz")
answer = predictor.predict(
passage=content,
question=question
)['best_span_str']
if answer:
return answer
else:
return "No answers for this question."
app.run(debug=True)