oopsie
Browse filesdouble pasted from my ide 😀
app.py
CHANGED
|
@@ -51,54 +51,4 @@ def predict():
|
|
| 51 |
if __name__ == '__main__':
|
| 52 |
print("starting ensemble api server", flush=True)
|
| 53 |
print("loading models on first request...", flush=True)
|
| 54 |
-
app.run(host='0.0.0.0', port=5000, debug=False)from flask import Flask, request, jsonify
|
| 55 |
-
from flask_cors import CORS
|
| 56 |
-
import os
|
| 57 |
-
import sys
|
| 58 |
-
|
| 59 |
-
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 60 |
-
from api.predict import predict_review
|
| 61 |
-
|
| 62 |
-
app = Flask(__name__)
|
| 63 |
-
CORS(app)
|
| 64 |
-
|
| 65 |
-
@app.route('/health', methods=['GET'])
|
| 66 |
-
def health():
|
| 67 |
-
return jsonify({"status": "ok"}), 200
|
| 68 |
-
|
| 69 |
-
@app.route('/predict', methods=['POST'])
|
| 70 |
-
def predict():
|
| 71 |
-
try:
|
| 72 |
-
data = request.get_json()
|
| 73 |
-
|
| 74 |
-
if not data or 'text' not in data:
|
| 75 |
-
return jsonify({"error": "missing 'text' field"}), 400
|
| 76 |
-
|
| 77 |
-
reviewText = data['text']
|
| 78 |
-
|
| 79 |
-
if not isinstance(reviewText, str):
|
| 80 |
-
return jsonify({"error": "'text' must be a string"}), 400
|
| 81 |
-
|
| 82 |
-
if len(reviewText.strip()) == 0:
|
| 83 |
-
return jsonify({"error": "text cannot be empty"}), 400
|
| 84 |
-
|
| 85 |
-
result = predict_review(reviewText)
|
| 86 |
-
|
| 87 |
-
return jsonify({
|
| 88 |
-
"prediction": result['prediction'],
|
| 89 |
-
"confidence": result['confidence'],
|
| 90 |
-
"is_fake": result['is_fake'],
|
| 91 |
-
"model_agreement": result['model_agreement'],
|
| 92 |
-
"fake_probability": result['fake_probability'],
|
| 93 |
-
"genuine_probability": result['genuine_probability'],
|
| 94 |
-
"length_category": result['length_category'],
|
| 95 |
-
"token_count": result['token_count']
|
| 96 |
-
}), 200
|
| 97 |
-
|
| 98 |
-
except Exception as e:
|
| 99 |
-
return jsonify({"error": str(e)}), 500
|
| 100 |
-
|
| 101 |
-
if __name__ == '__main__':
|
| 102 |
-
print("starting ensemble api server")
|
| 103 |
-
print("loading models on first request...")
|
| 104 |
-
app.run(host='0.0.0.0', port=5000, debug=False)
|
|
|
|
| 51 |
if __name__ == '__main__':
|
| 52 |
print("starting ensemble api server", flush=True)
|
| 53 |
print("loading models on first request...", flush=True)
|
| 54 |
+
app.run(host='0.0.0.0', port=5000, debug=False)from flask import Flask, request, jsonify
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|