JanetBackEnd/main_simple.py

34 lines
1.1 KiB
Python
Raw Normal View History

2023-04-08 04:04:24 +02:00
from flask import Flask, request, jsonify
from flask_cors import CORS, cross_origin
import os
2023-04-19 04:57:54 +02:00
import re
2023-04-08 04:04:24 +02:00
app = Flask(__name__)
url = os.getenv("FRONTEND_URL_WITH_PORT")
2023-04-08 15:15:18 +02:00
cors = CORS(app, resources={r"/api/predict": {"origins": url}, r"/api/feedback": {"origins": url}, r"/health": {"origins": '*'}})
2023-04-08 04:04:24 +02:00
@app.route("/health", methods=['GET'])
2023-04-08 15:15:18 +02:00
def health():
2023-04-08 04:04:24 +02:00
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__":
2023-04-19 04:57:54 +02:00
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))
2023-04-09 19:14:35 +02:00
app.run(host='0.0.0.0')