-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
29 lines (23 loc) · 792 Bytes
/
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
import json
import os
from flask import Flask, request, jsonify
import requests
import structlog
import settings
from transformers import pipeline
app = Flask(__name__)
nlp = pipeline('question-answering',model='YOUR MODEL PATH')
@app.route('/healthz', methods=['GET'], strict_slashes=False)
def healthz():
return jsonify({'status': 200})
@app.route('/search', methods=['GET','POST'])
def search():
request_data = request.get_json()
question = request_data['question']
context = request_data['context']
answer = nlp({'question': question,'context': context})
response = {'answer': answer}
print(f'Response: {json.dumps(response)}')
return jsonify(response)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=settings.PORT, debug=settings.DEBUG)