working_backend

This commit is contained in:
ahmed531998 2023-04-08 01:45:18 +02:00
parent 3aa8b4e53c
commit 44d66b334d
1 changed files with 12 additions and 6 deletions

18
main.py
View File

@ -24,21 +24,25 @@ from sentence_transformers import SentenceTransformer
app = Flask(__name__)
url = os.getenv("FRONTEND_URL_WITH_PORT")
cors = CORS(app, resources={r"/predict": {"origins": url}, r"/feedback": {"origins": url}, r"/health": {"origins": *}})
cors = CORS(app, resources={r"/api/predict": {"origins": url},
r"/api/feedback": {"origins": url},
r"/health": {"origins": "*"}
})
"""
conn = psycopg2.connect(
host="janet-pg",
database=os.getenv("POSTGRES_DB"),
user=os.getenv("POSTGRES_USER"),
password=os.getenv("POSTGRES_PASSWORD"))
"""
"""
conn = psycopg2.connect(host="https://janet-app-db.d4science.org",
database="janet",
user="janet_user",
password="2fb5e81fec5a2d906a04")
"""
cur = conn.cursor()
cur = conn.cursor()
"""
def vre_fetch():
while True:
@ -105,7 +109,7 @@ def predict():
def feedback():
data = request.get_json().get("feedback")
print(data)
"""
cur.execute('INSERT INTO feedback_trial (query, history, janet_modified_query, is_modified_query_correct, user_modified_query, 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)',
(data['query'], data['history'], data['modQuery'],
data['queryModCorrect'], data['correctQuery'],
@ -114,6 +118,7 @@ def feedback():
data['speed'], data['intent'])
)
conn.commit()
"""
reply = jsonify({"status": "done"})
return reply
@ -160,7 +165,7 @@ if __name__ == "__main__":
rg = ResponseGenerator(index,db, rec, generators, retriever)
"""
cur.execute('CREATE TABLE IF NOT EXISTS feedback_trial (id serial PRIMARY KEY,'
'query text NOT NULL,'
'history text NOT NULL,'
@ -177,4 +182,5 @@ if __name__ == "__main__":
'response_intent text NOT NULL);'
)
conn.commit()
"""
app.run(host='0.0.0.0', port=4000)