This commit is contained in:
ahmed531998 2023-04-21 03:56:34 +02:00
parent 1d8e052e39
commit b4e7e278a1
3 changed files with 16 additions and 40 deletions

View File

@ -2,12 +2,12 @@ FROM python:3.8.10-slim
WORKDIR /backend_janet WORKDIR /backend_janet
COPY requirements_main.txt . COPY requirements_simple.txt .
RUN pip install -r requirements_main.txt RUN pip install -r requirements_simple.txt
RUN rm -fr /root/.cache/* RUN rm -fr /root/.cache/*
COPY . . COPY . .
ENTRYPOINT ["python", "main.py"] ENTRYPOINT ["python", "main_simple.py"]

View File

@ -1,8 +1,8 @@
from flask import Flask, request, jsonify from flask import Flask, request, jsonify
from flask_cors import CORS, cross_origin from flask_cors import CORS, cross_origin
import os import os
import shutil
import re import re
import psycopg2
import requests import requests
import time import time
app = Flask(__name__) app = Flask(__name__)
@ -13,15 +13,7 @@ cors = CORS(app, resources={r"/api/predict": {"origins": url},
r"/health": {"origins": "*"} r"/health": {"origins": "*"}
}) })
users = {} 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']) @app.route("/health", methods=['GET'])
def health(): def health():
return "Success", 200 return "Success", 200
@ -58,35 +50,19 @@ def predict():
def feedback(): def feedback():
data = request.get_json().get("feedback") data = request.get_json().get("feedback")
print(data) 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"}) reply = jsonify({"status": "done"})
return reply return reply
if __name__ == "__main__": if __name__ == "__main__":
"""
cur.execute('CREATE TABLE IF NOT EXISTS feedback_experimental (id serial PRIMARY KEY,' folder = '/app'
'query text NOT NULL,' for filename in os.listdir(folder):
'history text NOT NULL,' file_path = os.path.join(folder, filename)
'janet_modified_query text NOT NULL,' try:
'is_modified_query_correct text NOT NULL,' if os.path.isfile(file_path) or os.path.islink(file_path):
'user_modified_query text, evidence_useful text NOT NULL,' os.unlink(file_path)
'response text NOT NULL,' elif os.path.isdir(file_path):
'preferred_response text,' shutil.rmtree(file_path)
'response_length_feedback text NOT NULL,' except Exception as e:
'response_fluency_feedback text NOT NULL,' print('Failed to delete %s. Reason: %s' % (file_path, e))
'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') app.run(host='0.0.0.0')

View File

@ -2,7 +2,7 @@ pandas==1.3.5
Flask==1.1.4 Flask==1.1.4
flask-cors==3.0.10 flask-cors==3.0.10
requests==2.25.1 requests==2.25.1
psycopg2==2.9.5 shutil
markupsafe==2.0.1 markupsafe==2.0.1
Werkzeug==1.0.1 Werkzeug==1.0.1