Skip to content

Commit

Permalink
Add API server
Browse files Browse the repository at this point in the history
  • Loading branch information
Javclaude committed May 31, 2020
1 parent ebc3f9e commit 3276eeb
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions app/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import argparse

import flask
from flask import Flask, jsonify, request
import requests

from utils import load_model, load_tokenizer, encode_text, predict
from transformers import AutoTokenizer

app = Flask(__name__)

Model, config_file = load_model("./src/Baseline_model/state_dict.py", "./src/Baseline_model/config_model.json") # argparse
tokenizer = load_tokenizer()

@app.route('/predict', methods = ['POST'])
def api_sentiment():
data = request.get_json(force = True)

encoded = encode_text(data['text'], tokenizer, config_file)

prediction = predict(Model, encoded)

request_responses = {
"Negative Score" : prediction[0][0],
"Positive Score" : prediction[0][1]
}

return jsonify(request_responses)

if __name__ == "__main__":

""" parser = argparse.ArgumentParser()
parser.add_argument("--path_to_model", help="Path to the pre trained model", typr=str)
parser.add_argument("--path_to_config", help="Path to the config file", type=str)
args = parser.parse_args()
"""
app.run(debug=True)






0 comments on commit 3276eeb

Please sign in to comment.