trial
This commit is contained in:
parent
f98a6bd103
commit
baa48bb7bd
|
@ -2,10 +2,10 @@ FROM python:3.8
|
|||
|
||||
WORKDIR /backend
|
||||
|
||||
COPY requirements_main.txt .
|
||||
COPY requirements_simple.txt .
|
||||
|
||||
RUN pip install -r requirements_main.txt
|
||||
RUN pip install -r requirements_simple.txt
|
||||
|
||||
COPY . .
|
||||
|
||||
ENTRYPOINT ["python", "main.py"]
|
||||
ENTRYPOINT ["python", "main_simple.py"]
|
||||
|
|
|
@ -5,12 +5,43 @@ 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": '*'}})
|
||||
cors = CORS(app, resources={r"/api/predict": {"origins": url},
|
||||
r"/api/feedback": {"origins": url},
|
||||
r"/api/dm": {"origins": url},
|
||||
r"/health": {"origins": "*"}
|
||||
})
|
||||
users = {}
|
||||
conn = psycopg2.connect(
|
||||
host="janet-pg",
|
||||
database=os.getenv("POSTGRES_DB"),
|
||||
user=os.getenv("POSTGRES_USER"),
|
||||
password=os.getenv("POSTGRES_PASSWORD"))
|
||||
|
||||
cur = conn.cursor()
|
||||
@app.route("/health", methods=['GET'])
|
||||
def health():
|
||||
return "Success", 200
|
||||
|
||||
@app.route("/api/dm", methods=['POST'])
|
||||
def init_dm():
|
||||
token = request.get_json().get("token")
|
||||
status = request.get_json().get("stat")
|
||||
if status == "start":
|
||||
message = {"stat": "waiting"}
|
||||
elif status == "set":
|
||||
headers = {"gcube-token": token, "Accept": "application/json"}
|
||||
if token not in users:
|
||||
url = 'https://api.d4science.org/rest/2/people/profile'
|
||||
response = requests.get(url, headers=headers)
|
||||
if response.status_code == 200:
|
||||
username = response.json()['result']['username']
|
||||
name = response.json()['result']['fullname']
|
||||
message = {"stat": "done"}
|
||||
else:
|
||||
message = {"stat": "rejected"}
|
||||
else:
|
||||
message = {"stat": "done"}
|
||||
return message
|
||||
@app.route("/api/predict", methods=['POST'])
|
||||
def predict():
|
||||
text = request.get_json().get("message")
|
||||
|
@ -21,13 +52,34 @@ def predict():
|
|||
@app.route('/api/feedback', methods = ['POST'])
|
||||
def feedback():
|
||||
data = request.get_json().get("feedback")
|
||||
print(data)
|
||||
|
||||
cur.execute('INSERT INTO feedback_experimental (query, history, janet_modified_query, is_modified_query_correct, user_modified_query, evidence_useful, response, preferred_response, response_length_feedback, response_fluency_feedback, response_truth_feedback, response_useful_feedback, response_time_feedback, response_intent) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)',
|
||||
(data['query'], data['history'], data['modQuery'],
|
||||
data['queryModCorrect'], data['correctQuery'], data['evidence'], data['janetResponse'], data['preferredResponse'], data['length'],
|
||||
data['fluency'], data['truthfulness'], data['usefulness'],
|
||||
data['speed'], data['intent'])
|
||||
)
|
||||
conn.commit()
|
||||
|
||||
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))
|
||||
cur.execute('CREATE TABLE IF NOT EXISTS feedback_experimental (id serial PRIMARY KEY,'
|
||||
'query text NOT NULL,'
|
||||
'history text NOT NULL,'
|
||||
'janet_modified_query text NOT NULL,'
|
||||
'is_modified_query_correct text NOT NULL,'
|
||||
'user_modified_query text, evidence_useful text NOT NULL,'
|
||||
'response text NOT NULL,'
|
||||
'preferred_response text,'
|
||||
'response_length_feedback text NOT NULL,'
|
||||
'response_fluency_feedback text NOT NULL,'
|
||||
'response_truth_feedback text NOT NULL,'
|
||||
'response_useful_feedback text NOT NULL,'
|
||||
'response_time_feedback text NOT NULL,'
|
||||
'response_intent text NOT NULL);'
|
||||
)
|
||||
conn.commit()
|
||||
app.run(host='0.0.0.0')
|
||||
|
|
Loading…
Reference in New Issue