tuyen4656789 commited on
Commit
ef53edc
·
verified ·
1 Parent(s): 81c27f7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request
2
+ import json
3
+ from QuestionAnsweringSystem.QuestionAnswer import get_answer_using_bert
4
+ app=Flask(__name__)
5
+
6
+ @app.route ("/questionAnswering", methods=['POST'])
7
+ def questionAnswering():
8
+ try:
9
+ json_data = request.get_json(force=True)
10
+ query = json_data['query']
11
+ context_list = json_data['context_list']
12
+ result = []
13
+ for val in context_list:
14
+ context = val['context']
15
+ context = context.replace("\n"," ")
16
+ answer_json_final = dict()
17
+ answer = get_answer_using_bert(context, query)
18
+ answer_json_final['answer'] = answer
19
+ answer_json_final['id'] = val['id']
20
+ answer_json_final['question'] = query
21
+ result.append(answer_json_final)
22
+
23
+ result={'results':result}
24
+ result = json.dumps(result)
25
+ return result
26
+
27
+ except Exception as e:
28
+ return {"Error": str(e)}
29
+
30
+ if __name__ == "__main__" :
31
+ app.run(debug=True,port="5001")