File size: 721 Bytes
36da459 |
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 |
from flask import Flask, jsonify, request
from utils import predict_single, predict_batch
app = Flask(__name__)
@app.route('/')
@app.route('/home')
def status():
return jsonify({'status': 'ok'})
@app.route('/predict', methods=['POST'])
def predict():
data = request.get_json()
if 'text' not in data:
return jsonify({'error': 'Missing "text" parameter'}), 400
tweets = data['text']
if len(tweets) == 1:
response = predict_single(tweets[0])
elif len(tweets) > 1:
response = predict_batch(tweets)
else:
return jsonify({'error': 'Zero text strings posted'}), 400
return jsonify({
'inputs': tweets,
'predictions': response
}) |