This commit is contained in:
ahmed531998 2023-04-21 03:56:34 +02:00
parent 8c052c9588
commit 179e942e46
3 changed files with 16 additions and 40 deletions

View File

@ -2,12 +2,12 @@ FROM python:3.8.10-slim
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/*
COPY . .
ENTRYPOINT ["python", "main.py"]
ENTRYPOINT ["python", "main_simple.py"]

View File

@ -1,8 +1,8 @@
from flask import Flask, request, jsonify
from flask_cors import CORS, cross_origin
import os
import shutil
import re
import psycopg2
import requests
import time
app = Flask(__name__)
@ -13,15 +13,7 @@ cors = CORS(app, resources={r"/api/predict": {"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
@ -58,35 +50,19 @@ def predict():
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__":
"""
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()
"""
folder = '/app'
for filename in os.listdir(folder):
file_path = os.path.join(folder, filename)
try:
if os.path.isfile(file_path) or os.path.islink(file_path):
os.unlink(file_path)
elif os.path.isdir(file_path):
shutil.rmtree(file_path)
except Exception as e:
print('Failed to delete %s. Reason: %s' % (file_path, e))
app.run(host='0.0.0.0')

View File

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