Skip to content

Commit

Permalink
Demo UI add env vars & other small fixes (deepset-ai#1828)
Browse files Browse the repository at this point in the history
* Add more env vars to the streamlit ui

* Add some more questions to the random ones

* Relax a statuscode check and rename env vars

* Make query error message more descriptive

* Add log message

* Align docker-compose with and without GPU

* Typo in pipeline filename

* Remove prefix from var in docker_compose

* Align docker-compose.yml and add small sleep to the initialized poller to prevent spamming

* Fix the name of the dockerfile used to build the GPU image
  • Loading branch information
ZanSara authored Nov 30, 2021
1 parent 56e4e84 commit 935689e
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 13 deletions.
10 changes: 8 additions & 2 deletions docker-compose-gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
haystack-api:
build:
context: .
dockerfile: Dockerfile
dockerfile: Dockerfile-GPU
image: "deepset/haystack-gpu:latest"
# in recent docker-compose version you can enable GPU resources. Make sure to fulfill the prerequisites listed here: https://docs.docker.com/compose/gpu-support/
deploy:
Expand Down Expand Up @@ -52,5 +52,11 @@ services:
environment:
- API_ENDPOINT=http://haystack-api:8000
- EVAL_FILE=eval_labels_example.csv
- HAYSTACK_UI_DISABLE_FILE_UPLOAD # docker-compose run -e HAYSTACK_UI_DISABLE_FILE_UPLOAD=1 ...
# The value fot 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 && streamlit run webapp.py'"
11 changes: 10 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ services:
environment:
# See rest_api/pipelines.yaml for configurations of Search & Indexing Pipeline.
- DOCUMENTSTORE_PARAMS_HOST=elasticsearch
- PIPELINE_YAML_PATH=/home/user/rest_api/pipeline/pipelines.yaml
- CONCURRENT_REQUEST_PER_WORKER
depends_on:
- elasticsearch
command: "/bin/bash -c 'sleep 10 && gunicorn rest_api.application:app -b 0.0.0.0 -k uvicorn.workers.UvicornWorker --workers 1 --timeout 180'"
command: "/bin/bash -c 'sleep 10 && gunicorn rest_api.application:app -b 0.0.0.0 -k uvicorn.workers.UvicornWorker --workers 8 --timeout 180'"
elasticsearch:
# This will start an empty elasticsearch instance (so you have to add your documents yourself)
#image: "elasticsearch:7.9.2"
Expand All @@ -39,4 +41,11 @@ services:
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.
# 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 && streamlit run webapp.py'"
1 change: 1 addition & 0 deletions rest_api/controller/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
logging.info(f"Loaded pipeline nodes: {PIPELINE.graph.nodes.keys()}")

concurrency_limiter = RequestLimiter(CONCURRENT_REQUEST_PER_WORKER)
logging.info("Concurrent requests per worker: {CONCURRENT_REQUEST_PER_WORKER}")


@router.get("/initialized")
Expand Down
15 changes: 12 additions & 3 deletions ui/eval_labels_example.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
"Question Text";"Answer"
"What's the capital of France?";"Paris"
"What's the tallest mountain in Kenya?";"Mount Kenya"
"What's the climate of Beijing?";"humid continental"
"What is the capital of the Netherlands?";"Amsterdam"
"What's the tallest mountain in Africa?";"Mount Kilimanjaro"
"What's the climate of Beijing?";"monsoon-influenced humid continental"
"What's the longest river of Europe?";"The Volga"
"What's the deepest lake in the world?";"Lake Bajkal"
"How many people live in the capital of the US?";"689,545"
"Which Chinese ciy is the largest?";"Shanghai"
"What's the type of government of the UK?";"unitary parliamentary democracy and constitutional monarchy"
"What currency is used in Hungary?";"Hungarian forint"
"In which city is the Louvre?";"Paris"
"Which language is spoken in the Fiji?";"Fiji Hindi"
"Who is the current king of Spain?";"Felipe VI"
6 changes: 4 additions & 2 deletions ui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import logging
import requests
from time import sleep
from uuid import uuid4
import streamlit as st

Expand All @@ -25,6 +26,7 @@ def haystack_is_ready():
return True
except Exception as e:
logging.exception(e)
sleep(1) # To avoid spamming a non-existing endpoint at startup
return False


Expand All @@ -48,8 +50,8 @@ def query(query, filters={}, top_k_reader=5, top_k_retriever=5) -> Tuple[List[Di
req = {"query": query, "params": params}
response_raw = requests.post(url, json=req)

if response_raw.status_code >= 400:
raise Exception(f"{response_raw}")
if response_raw.status_code >= 400 and response_raw.status_code != 503:
raise Exception(f"{vars(response_raw)}")

response = response_raw.json()
if "errors" in response:
Expand Down
26 changes: 21 additions & 5 deletions ui/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@


# Adjust to a question that you would like users to see in the search bar when they load the UI:
DEFAULT_QUESTION_AT_STARTUP = "What's the capital of France?"
DEFAULT_QUESTION_AT_STARTUP = os.getenv("DEFAULT_QUESTION_AT_STARTUP", "What's the capital of France?")

# Sliders
DEFAULT_DOCS_FROM_RETRIEVER = int(os.getenv("DEFAULT_DOCS_FROM_RETRIEVER", 3))
DEFAULT_NUMBER_OF_ANSWERS = int(os.getenv("DEFAULT_NUMBER_OF_ANSWERS", 3))

# Labels for the evaluation
EVAL_LABELS = os.getenv("EVAL_FILE", Path(__file__).parent / "eval_labels_example.csv")

# Whether the file upload should be enabled or not
DISABLE_FILE_UPLOAD = os.getenv("HAYSTACK_UI_DISABLE_FILE_UPLOAD")
DISABLE_FILE_UPLOAD = bool(os.getenv("DISABLE_FILE_UPLOAD"))


def main():
Expand Down Expand Up @@ -54,8 +58,20 @@ def reset_results(*args):

# Sidebar
st.sidebar.header("Options")
top_k_reader = st.sidebar.slider("Max. number of answers", min_value=1, max_value=10, value=3, step=1, on_change=reset_results)
top_k_retriever = st.sidebar.slider("Max. number of documents from retriever", min_value=1, max_value=10, value=3, step=1, on_change=reset_results)
top_k_reader = st.sidebar.slider(
"Max. number of answers",
min_value=1,
max_value=10,
value=DEFAULT_NUMBER_OF_ANSWERS,
step=1,
on_change=reset_results)
top_k_retriever = st.sidebar.slider(
"Max. number of documents from retriever",
min_value=1,
max_value=10,
value=DEFAULT_DOCS_FROM_RETRIEVER,
step=1,
on_change=reset_results)
eval_mode = st.sidebar.checkbox("Evaluation mode")
debug = st.sidebar.checkbox("Show debug info")

Expand Down Expand Up @@ -158,7 +174,7 @@ def reset_results(*args):
return
except Exception as e:
logging.exception(e)
if "The server is busy processing requests" in str(e):
if "The server is busy processing requests" in str(e) or "503" in str(e):
st.error("🧑‍🌾    All our workers are busy! Try again later.")
else:
st.error("🐞    An error occurred during the request.")
Expand Down

0 comments on commit 935689e

Please sign in to comment.