backend_working

This commit is contained in:
ahmed531998 2023-04-08 02:38:44 +02:00
parent 44d66b334d
commit be4a1ec4c5
1 changed files with 10 additions and 10 deletions

20
main.py
View File

@ -28,21 +28,21 @@ 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:
@ -86,14 +86,14 @@ def predict():
state['help'] = False
state['inactive'] = False
old_user_interests = user.get_user_interests()
old_vre_material = pd.concat([vre.db['paper_db'], vre.db['dataset_db']]).drop_duplicates(keep=False).reset_index(drop=True)
old_vre_material = pd.concat([vre.db['paper_db'], vre.db['dataset_db']]).reset_index(drop=True)
user_interests = []
for entity in state['entities']:
if entity['entity'] == 'TOPIC':
user_interests.append(entity['value'])
user.update_interests(user_interests)
new_user_interests = user.get_user_interests()
new_vre_material = pd.concat([vre.db['paper_db'], vre.db['dataset_db']]).drop_duplicates(keep=False).reset_index(drop=True)
new_vre_material = pd.concat([vre.db['paper_db'], vre.db['dataset_db']]).reset_index(drop=True)
if (new_user_interests() != old_user_interests or old_vre_material != new_vre_material):
rec.generate_recommendations(new_user_interests, new_vre_material)
dm.update(state)
@ -109,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'],
@ -118,7 +118,7 @@ def feedback():
data['speed'], data['intent'])
)
conn.commit()
"""
reply = jsonify({"status": "done"})
return reply
@ -165,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,'
@ -182,5 +182,5 @@ if __name__ == "__main__":
'response_intent text NOT NULL);'
)
conn.commit()
"""
app.run(host='0.0.0.0', port=4000)