Skip to content

Commit

Permalink
Merge pull request #3 from WSE-research/addChanges
Browse files Browse the repository at this point in the history
Add changes
  • Loading branch information
dschiese authored Jun 18, 2024
2 parents e71584a + 7a92b09 commit 14b5f41
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ on: push
jobs:
build:
runs-on: ubuntu-latest
env:
FEEDBACK_URL: ${{ secrets.URL_MONGO }}
MONGO_USER: ${{ secrets.USER_MONGO }}
MONGO_PASSWORD: ${{ secrets.PASSWORD_MONGO }}
MONGO_AUTHSOURCE: ${{ secrets.AUTHSOURCE_MONGO }}
GITHUB_WORKSPACE: ${{github.workspace}}

steps:
- uses: actions/checkout@v4
- name: Save tag to file if release
Expand All @@ -16,6 +23,8 @@ jobs:
- 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
- name: Replace secrets in env file
uses: WSE-research/actions-replace-env-variables@v0.1.4
- name: Docker Login
if: startsWith(github.ref, 'refs/tags/')
uses: docker/login-action@v3
Expand Down
31 changes: 21 additions & 10 deletions explanation_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -269,34 +278,36 @@ def showExplanationContainer(component, lang, plainKey, datasetTitle):
st.markdown(f"""<div style="margin-bottom: 25px;">{template}</div>""", 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"""<h3>Generative</h3>""", unsafe_allow_html=True)
st.markdown(f"""<div style="margin-bottom: 25px;">{generative}</div>""", 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.")
Expand Down
5 changes: 4 additions & 1 deletion service_config/files/.env
Original file line number Diff line number Diff line change
Expand Up @@ -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=
FEEDBACK_URL=placeholder
USER_MONGO=placeholder
PASSWORD_MONGO=placeholder
AUTHSOURCE_MONGO=placeholder

0 comments on commit 14b5f41

Please sign in to comment.