From 7d0f89b6f5a0c6a215e83db40a0b52700bdd4d4e Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Fri, 14 Oct 2022 18:16:20 +0200 Subject: [PATCH] fix: demo won't start through Docker compose (#3337) * use new Docker images and add a health check for ES * try * silence streamlit errors * remove CMD override * final touches * leftover * make pylint happy --- docker-compose.yml | 42 +++++++++++++++++++++--------------------- ui/Dockerfile | 14 +++++--------- ui/webapp.py | 12 ++++++++++-- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index d2fa713b5..99da583fb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,30 +1,23 @@ -version: "3" services: + haystack-api: - build: - context: . - dockerfile: Dockerfile - image: "deepset/haystack-cpu:latest" - # Mount custom Pipeline YAML and custom Components. - # volumes: - # - ./rest_api/pipeline:/home/user/rest_api/pipeline + # Pull Haystack's latest commit + image: "deepset/haystack:cpu-main" ports: - 8000:8000 restart: on-failure environment: # See rest_api/pipeline/pipelines.haystack-pipeline.yml for configurations of Search & Indexing Pipeline. - DOCUMENTSTORE_PARAMS_HOST=elasticsearch - - PIPELINE_YAML_PATH=/home/user/rest_api/rest_api/pipeline/pipelines.haystack-pipeline.yml - - CONCURRENT_REQUEST_PER_WORKER + - PIPELINE_YAML_PATH=/opt/venv/lib/python3.10/site-packages/rest_api/pipeline/pipelines.haystack-pipeline.yml + - QUERY_PIPELINE_NAME=query + - TOKENIZERS_PARALLELISM=false depends_on: - - elasticsearch - # Starts REST API with only 2 workers so that it can be run on systems with just 4GB of memory - # If you need to handle large loads of incoming requests and have memory to spare, consider increasing the number of workers - command: "/bin/bash -c 'sleep 10 && gunicorn rest_api.application:app -b 0.0.0.0 -k uvicorn.workers.UvicornWorker --workers 2 --timeout 180'" + elasticsearch: + condition: service_healthy + elasticsearch: - # This will start an empty elasticsearch instance (so you have to add your documents yourself) - #image: "elasticsearch:7.9.2" - # If you want a demo image instead that is "ready-to-query" with some indexed articles + # This image is "ready-to-query" with some indexed articles # about countries and capital cities from Wikipedia: image: "deepset/elasticsearch-countries-and-capitals" ports: @@ -32,22 +25,29 @@ services: restart: on-failure environment: - discovery.type=single-node + - "ES_JAVA_OPTS=-Xms1024m -Xmx1024m" + healthcheck: + test: curl --fail http://localhost:9200/_cat/health || exit 1 + interval: 10s + timeout: 1s + retries: 10 + ui: + depends_on: + - haystack-api build: context: ui dockerfile: Dockerfile - image: "deepset/haystack-streamlit-ui:latest" ports: - 8501:8501 restart: on-failure environment: - API_ENDPOINT=http://haystack-api:8000 - - EVAL_FILE=eval_labels_example.csv - # The value fot the following variables will be read from the host, if present. + - EVAL_FILE=ui/eval_labels_example.csv + # The value of the following variables will be read from the host, if present. # They can also be temporarily set for docker-compose, for example: # DISABLE_FILE_UPLOAD=1 DEFAULT_DOCS_FROM_RETRIEVER=5 docker-compose up - DISABLE_FILE_UPLOAD - DEFAULT_QUESTION_AT_STARTUP - DEFAULT_DOCS_FROM_RETRIEVER - DEFAULT_NUMBER_OF_ANSWERS - command: "/bin/bash -c 'sleep 15 && python -m streamlit run ui/webapp.py'" diff --git a/ui/Dockerfile b/ui/Dockerfile index 7fdbb5cef..b88d1a4a1 100644 --- a/ui/Dockerfile +++ b/ui/Dockerfile @@ -1,20 +1,16 @@ FROM python:3.7.4-stretch -WORKDIR /home/user - -RUN apt-get update && apt-get install -y curl git pkg-config cmake +# RUN apt-get update && apt-get install -y curl git pkg-config cmake # copy code RUN mkdir ui/ -COPY setup.py /home/user/ui -COPY utils.py /home/user/ui -COPY webapp.py /home/user/ui -COPY eval_labels_example.csv /home/user/ +COPY . /opt/ui # install as a package -RUN pip install --upgrade pip -RUN pip install ui/ +RUN pip install --upgrade pip && \ + pip install /opt/ui/ +WORKDIR /opt EXPOSE 8501 # cmd for running the API diff --git a/ui/webapp.py b/ui/webapp.py index 04b93e9d4..7a66e7838 100644 --- a/ui/webapp.py +++ b/ui/webapp.py @@ -88,7 +88,9 @@ Ask any question on this topic and see if Haystack can find the correct answer t # File upload block if not DISABLE_FILE_UPLOAD: st.sidebar.write("## File Upload:") - data_files = st.sidebar.file_uploader("", type=["pdf", "txt", "docx"], accept_multiple_files=True) + data_files = st.sidebar.file_uploader( + "upload", type=["pdf", "txt", "docx"], accept_multiple_files=True, label_visibility="hidden" + ) for data_file in data_files: # Upload file if data_file: @@ -143,7 +145,13 @@ Ask any question on this topic and see if Haystack can find the correct answer t ) # Search bar - question = st.text_input("", value=st.session_state.question, max_chars=100, on_change=reset_results) + question = st.text_input( + value=st.session_state.question, + max_chars=100, + on_change=reset_results, + label="question", + label_visibility="hidden", + ) col1, col2 = st.columns(2) col1.markdown("", unsafe_allow_html=True) col2.markdown("", unsafe_allow_html=True)