2023-04-08 03:33:28 +02:00
|
|
|
from flask import Flask, request, jsonify
|
2023-03-30 15:17:54 +02:00
|
|
|
from flask_cors import CORS, cross_origin
|
2023-04-08 03:33:28 +02:00
|
|
|
import os
|
2023-03-30 20:14:13 +02:00
|
|
|
|
2023-03-30 15:17:54 +02:00
|
|
|
app = Flask(__name__)
|
|
|
|
url = os.getenv("FRONTEND_URL_WITH_PORT")
|
2023-04-08 03:33:28 +02:00
|
|
|
cors = CORS(app, resources={r"/predict": {"origins": url}, r"/feedback": {"origins": url}})
|
2023-03-30 15:17:54 +02:00
|
|
|
|
2023-04-07 17:35:51 +02:00
|
|
|
@app.route("/health", methods=['GET'])
|
|
|
|
def check_health():
|
|
|
|
return "Success", 200
|
|
|
|
|
2023-04-07 18:27:07 +02:00
|
|
|
@app.route("/api/predict", methods=['POST'])
|
2023-03-30 15:17:54 +02:00
|
|
|
def predict():
|
|
|
|
text = request.get_json().get("message")
|
2023-04-08 03:33:28 +02:00
|
|
|
message = {"answer": "answer", "query": "text", "cand": "candidate", "history": "history", "modQuery": "modQuery"}
|
2023-03-30 15:17:54 +02:00
|
|
|
reply = jsonify(message)
|
|
|
|
return reply
|
|
|
|
|
2023-04-07 18:27:07 +02:00
|
|
|
@app.route('/api/feedback', methods = ['POST'])
|
2023-03-30 15:17:54 +02:00
|
|
|
def feedback():
|
2023-04-07 03:23:01 +02:00
|
|
|
data = request.get_json().get("feedback")
|
2023-03-30 15:17:54 +02:00
|
|
|
reply = jsonify({"status": "done"})
|
|
|
|
return reply
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2023-04-07 21:03:43 +02:00
|
|
|
app.run(host='0.0.0.0', port=4000)
|