codingcoolfun9ed commited on
Commit
0abefef
·
verified ·
1 Parent(s): d31cc65

overhaul for v___ AHHHH

Browse files
Files changed (1) hide show
  1. api/app.py +62 -3
api/app.py CHANGED
@@ -9,6 +9,59 @@ from api.predict import predict_review
9
  app = Flask(__name__)
10
  CORS(app)
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  @app.route('/health', methods=['GET'])
13
  def health():
14
  return jsonify({"status": "ok"}), 200
@@ -34,12 +87,18 @@ def predict():
34
  return jsonify({
35
  "prediction": result['prediction'],
36
  "confidence": result['confidence'],
37
- "is_fake": result['is_fake']
 
 
 
 
 
38
  }), 200
39
 
40
  except Exception as e:
41
  return jsonify({"error": str(e)}), 500
42
 
43
  if __name__ == '__main__':
44
- print("starting api server")
45
- app.run(host='0.0.0.0', port=5000, debug=False)
 
 
9
  app = Flask(__name__)
10
  CORS(app)
11
 
12
+ @app.route('/health', methods=['GET'])
13
+ def health():
14
+ return jsonify({"status": "ok", "model": "ensemble-v1"}), 200
15
+
16
+ @app.route('/predict', methods=['POST'])
17
+ def predict():
18
+ try:
19
+ data = request.get_json()
20
+
21
+ if not data or 'text' not in data:
22
+ return jsonify({"error": "missing 'text' field"}), 400
23
+
24
+ reviewText = data['text']
25
+
26
+ if not isinstance(reviewText, str):
27
+ return jsonify({"error": "'text' must be a string"}), 400
28
+
29
+ if len(reviewText.strip()) == 0:
30
+ return jsonify({"error": "text cannot be empty"}), 400
31
+
32
+ result = predict_review(reviewText)
33
+
34
+ if "error" in result and result["prediction"] == "error":
35
+ return jsonify(result), 400
36
+
37
+ return jsonify({
38
+ "prediction": result['prediction'],
39
+ "confidence": result['confidence'],
40
+ "is_fake": result['is_fake'],
41
+ "model_agreement": result['model_agreement'],
42
+ "fake_probability": result['fake_probability'],
43
+ "genuine_probability": result['genuine_probability'],
44
+ "length_category": result['length_category'],
45
+ "token_count": result['token_count']
46
+ }), 200
47
+
48
+ except Exception as e:
49
+ return jsonify({"error": str(e)}), 500
50
+
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
 
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)