from flask import Flask, jsonify, request | |
from utils import predict_single, predict_batch | |
app = Flask(__name__) | |
def status(): | |
return jsonify({'status': 'ok'}) | |
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 | |
}) | |
if __name__ == '__main__': | |
app.run(debug=True, host='0.0.0.0', port=9696) | |