-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
49ba859
commit 5cf9618
Showing
2 changed files
with
22 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
from flask import Flask | ||
from flask_restful import Resource, Api | ||
from flask import Flask, request, jsonify | ||
|
||
import os | ||
from ast import literal_eval | ||
import pandas as pd | ||
|
||
from cdqa.utils.converter import filter_paragraphs | ||
from cdqa.reader.bertqa_sklearn import BertQA | ||
from cdqa.pipeline.qa_pipeline import QAPipeline | ||
|
||
app = Flask(__name__) | ||
api = Api(app) | ||
|
||
class HelloWorld(Resource): | ||
def get(self): | ||
return {'hello': 'world'} | ||
df = pd.read_csv('../data/bnpp_newsroom_v1.0/bnpp_newsroom-v1.0.csv', converters={'paragraphs': literal_eval}) | ||
df['paragraphs'] = df['paragraphs'].apply(filter_paragraphs) | ||
df['content'] = df['paragraphs'].apply(lambda x: ' '.join(x)) | ||
|
||
api.add_resource(HelloWorld, '/') | ||
qa_pipe = QAPipeline(model = '../models/bert_qa_squad_vCPU/bert_qa_squad_vCPU-sklearn.joblib') | ||
qa_pipe.fit(df) | ||
|
||
if __name__ == '__main__': | ||
app.run(debug=True) | ||
@app.route('/api', methods=['GET']) | ||
def api(): | ||
query = request.query_string | ||
prediction = qa_pipe.answer(query) | ||
return jsonify(query=query, | ||
prediction=prediction) |