JanetBackEnd/main_simple.py

34 lines
1.1 KiB
Python

from flask import Flask, request, jsonify
from flask_cors import CORS, cross_origin
import os
import re
app = Flask(__name__)
url = os.getenv("FRONTEND_URL_WITH_PORT")
cors = CORS(app, resources={r"/api/predict": {"origins": url}, r"/api/feedback": {"origins": url}, r"/health": {"origins": '*'}})
@app.route("/health", methods=['GET'])
def health():
return "Success", 200
@app.route("/api/predict", methods=['POST'])
def predict():
text = request.get_json().get("message")
message = {"answer": "answer", "query": "text", "cand": "candidate", "history": "history", "modQuery": "modQuery"}
reply = jsonify(message)
return reply
@app.route('/api/feedback', methods = ['POST'])
def feedback():
data = request.get_json().get("feedback")
reply = jsonify({"status": "done"})
return reply
if __name__ == "__main__":
for f in os.listdir("/app/"):
if re.search("^assistedlab_", f):
os.remove(os.path.join("/app/", f))
if re.search("^janet_",f):
os.remove(os.path.join("/app/", f))
app.run(host='0.0.0.0')