From 7e96d716e39a2565bdd1a05422dffab70bab2623 Mon Sep 17 00:00:00 2001 From: Dennis Schiese Date: Tue, 18 Jun 2024 14:12:34 +0200 Subject: [PATCH] Addedmongodb feedback --- .github/workflows/docker-image.yml | 8 ++++++++ explanation_frontend.py | 31 ++++++++++++++++++++---------- service_config/files/.env | 5 ++++- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 71ad412..18652ea 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -2,6 +2,12 @@ name: Docker Image CI on: push +env: + FEEDBACK_URL: ${{ secrets.URL_MONGO }} + MONGO_USER: ${{ secrets.USER_MONGO }} + MONGO_PASSWORD: ${{ secrets.PASSWORD_MONGO }} + MONGO_AUTHSOURCE: ${{ secrets.AUTHSOURCE_MONGO }} + jobs: build: runs-on: ubuntu-latest @@ -13,6 +19,8 @@ jobs: - name: Build the Docker image for temporary use only if: ${{ ! startsWith(github.ref, 'refs/tags/') }} run: docker build . --file Dockerfile --tag tmp:latest + - name: Replace env with secrets + run: wseresearch/ actions-replace-env-variables:v0.1.4 - name: Build the Docker image for tag release if: startsWith(github.ref, 'refs/tags/') run: docker build . --file Dockerfile --tag ${{ secrets.DOCKER_IMAGE_NAME }}:latest diff --git a/explanation_frontend.py b/explanation_frontend.py index 82a2593..8e210bb 100644 --- a/explanation_frontend.py +++ b/explanation_frontend.py @@ -7,6 +7,7 @@ from code_editor import code_editor import pandas as pd from decouple import config +import pymongo st.set_page_config(layout="wide") include_css(st, ["css/style_github_ribbon.css"]) @@ -131,6 +132,14 @@ if "showPreconfigured" not in st.session_state: st.session_state.showPreconfigured = True; +mongo_client = pymongo.MongoClient(config('FEEDBACK_URL'), + username=config('MONGO_USER'), + password=config('MONGO_PASSWORD'), + authSource=config('MONGO_AUTHSOURCE'), +) +explanationsDb = mongo_client["explanations"] +explanationsCol = explanationsDb["explanation"] + ###### FUNCTIONS # Fetches the available components from the associated Qanary pipeline @@ -269,34 +278,36 @@ def showExplanationContainer(component, lang, plainKey, datasetTitle): st.markdown(f"""
{template}
""", unsafe_allow_html=True) placeholder1, col1, col2, placeholder2 = st.columns(4) with col1: - feedback_button(plainKey+"template"+"correct",":white_check_mark:", "template", template, FEEDBACK_GOOD) + feedback_button(plainKey+"template"+"correct",":white_check_mark:", "template", template, plainKey, FEEDBACK_GOOD) with col2: - feedback_button(plainKey+"template"+"wrong",":x:", "template", template, FEEDBACK_BAD) + feedback_button(plainKey+"template"+"wrong",":x:", "template", template, plainKey, FEEDBACK_BAD) with generativeCol: st.markdown(f"""

Generative

""", unsafe_allow_html=True) st.markdown(f"""
{generative}
""", unsafe_allow_html=True) placeholder1, col1, col2, placeholder2 = st.columns(4) with col1: - feedback_button(plainKey+"generative"+"correct",":white_check_mark:", "generative", generative, FEEDBACK_GOOD) + feedback_button(plainKey+"generative"+"correct",":white_check_mark:", "generative", generative, plainKey, FEEDBACK_GOOD) with col2: - feedback_button(plainKey+"generative"+"wrong",":x:", "generative", generative, FEEDBACK_BAD) + feedback_button(plainKey+"generative"+"wrong",":x:", "generative", generative, plainKey, FEEDBACK_BAD) -def feedback_button(key, icon, type, explanation, feedback): +def feedback_button(key, icon, type, explanation, datatype, feedback): if st.button(icon, key=key, type="secondary"): - send_feedback(explanation=explanation, explanation_type=type, feedback=feedback) + send_feedback(explanation=explanation, explanation_type=type, datatype=datatype, feedback=feedback) st.toast(get_random_element(feedback_messages), icon=get_random_element(feedback_icons)) -def send_feedback(explanation, explanation_type, feedback): - try: - response = requests.post(FEEDBACK_URL, json= { +def send_feedback(explanation, explanation_type, datatype, feedback): + json= { "graph": st.session_state.currentQaProcessExplanations["meta_information"]["graphUri"], "component": st.session_state.selected_component, "explanation": explanation, "explanation_type": explanation_type, + "datatype": datatype, "gpt_model": st.session_state.selected_gptModel["concrete_model"], "shots": st.session_state.selected_gptModel["shots"], "feedback": feedback - }) + } + try: + response = explanationsCol.insert_one(json) except Exception as e: logging.error("Feedback wasn't sent: " + str(e)) st.error("Feedback wasn't sent. Sorry for the circumstances.") diff --git a/service_config/files/.env b/service_config/files/.env index 10efe9c..e80d7cb 100644 --- a/service_config/files/.env +++ b/service_config/files/.env @@ -2,4 +2,7 @@ QANARY_PIPELINE_URL=http://demos.swe.htwk-leipzig.de:40111 QANARY_EXPLANATION_SERVICE_URL=http://demos.swe.htwk-leipzig.de:40190 QANARY_PIPELINE_COMPONENTS=http://demos.swe.htwk-leipzig.de:40111/components GITHUB_REPO=https://github.com/WSE-research/qanary-explanainability-frontend -FEEDBACK_URL= \ No newline at end of file +FEEDBACK_URL=placeholder +USER_MONGO=placeholder +PASSWORD_MONGO=placeholder +AUTHSOURCE_MONGO=placeholder \ No newline at end of file