From 8c1a34494d281edec0bceefa42c8a04895ec5bca Mon Sep 17 00:00:00 2001 From: Stefano Fiorucci <44616784+anakin87@users.noreply.github.com> Date: Thu, 20 Oct 2022 12:18:03 +0200 Subject: [PATCH] refactor: update package strategy in ui (#3396) * update ui package: first try * update README * fixes * update schemas * restore schemas * use matrix folder in tests * fix tests * fix schemas * really fix schemas * don't use matrix folder * remove blank line * cleaner pytest command --- .github/workflows/tests.yml | 6 +-- ui/Dockerfile | 7 ++- ui/README.md | 4 +- ui/pyproject.toml | 73 +++++++++++++++++++++++++++++ ui/setup.py | 40 ---------------- ui/ui/__about__.py | 10 ++++ ui/{ => ui}/__init__.py | 0 ui/{ => ui}/eval_labels_example.csv | 0 ui/{ => ui}/utils.py | 0 ui/{ => ui}/webapp.py | 0 10 files changed, 91 insertions(+), 49 deletions(-) create mode 100644 ui/pyproject.toml delete mode 100644 ui/setup.py create mode 100644 ui/ui/__about__.py rename ui/{ => ui}/__init__.py (100%) rename ui/{ => ui}/eval_labels_example.csv (100%) rename ui/{ => ui}/utils.py (100%) rename ui/{ => ui}/webapp.py (100%) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7de575d11..70805b9d5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -82,7 +82,7 @@ jobs: - name: Pylint run: | - pylint -ry -j 0 haystack/ rest_api/rest_api ui/ + pylint -ry -j 0 haystack/ rest_api/rest_api ui/ui - uses: act10ns/slack@v1 with: @@ -627,7 +627,6 @@ jobs: strategy: matrix: os: [windows-latest, ubuntu-latest] - runs-on: ${{ matrix.os }} steps: @@ -643,7 +642,8 @@ jobs: - name: Run tests run: | - pytest ${{ env.PYTEST_PARAMS }} rest_api/ ui/ + pytest ${{ env.PYTEST_PARAMS }} rest_api/ + pytest ${{ env.PYTEST_PARAMS }} ui/ - uses: act10ns/slack@v1 with: diff --git a/ui/Dockerfile b/ui/Dockerfile index b88d1a4a1..523514815 100644 --- a/ui/Dockerfile +++ b/ui/Dockerfile @@ -3,14 +3,13 @@ FROM python:3.7.4-stretch # RUN apt-get update && apt-get install -y curl git pkg-config cmake # copy code -RUN mkdir ui/ -COPY . /opt/ui +COPY . /ui # install as a package RUN pip install --upgrade pip && \ - pip install /opt/ui/ + pip install /ui/ -WORKDIR /opt +WORKDIR /ui EXPOSE 8501 # cmd for running the API diff --git a/ui/README.md b/ui/README.md index 412d65c7b..0b84836d9 100644 --- a/ui/README.md +++ b/ui/README.md @@ -14,7 +14,7 @@ The UI interacts with the Haystack REST API. To get started with Haystack please Execute in this folder: ``` -streamlit run webapp.py +streamlit run ui/webapp.py ``` Requirements: This expects a running Haystack REST API at `http://localhost:8000` @@ -34,7 +34,7 @@ The evaluation mode leverages the feedback REST API endpoint of haystack. The us In order to use the UI in evaluation mode, you need an ElasticSearch instance with pre-indexed files and the Haystack REST API. You can set the environment up via docker images. For ElasticSearch, you can check out our [documentation](https://haystack.deepset.ai/usage/document-store#initialisation) and for setting up the REST API this [link](https://github.com/deepset-ai/haystack/blob/main/README.md#7-rest-api). -To enter the evaluation mode, select the checkbox "Evaluation mode" in the sidebar. The UI will load the predefined questions from the file [`eval_labels_examples`](https://raw.githubusercontent.com/deepset-ai/haystack/main/ui/eval_labels_example.csv). The file needs to be prefilled with your data. This way, the user will get a random question from the set and can give his feedback with the buttons below the questions. To load a new question, click the button "Get random question". +To enter the evaluation mode, select the checkbox "Evaluation mode" in the sidebar. The UI will load the predefined questions from the file [`eval_labels_examples`](https://raw.githubusercontent.com/deepset-ai/haystack/main/ui/ui/eval_labels_example.csv). The file needs to be prefilled with your data. This way, the user will get a random question from the set and can give his feedback with the buttons below the questions. To load a new question, click the button "Get random question". The file just needs to have two columns separated by semicolon. You can add more columns but the UI will ignore them. Every line represents a questions answer pair. The columns with the questions needs to be named “Question Text” and the answer column “Answer” so that they can be loaded correctly. Currently, the easiest way to create the file is manually by adding question answer pairs. diff --git a/ui/pyproject.toml b/ui/pyproject.toml new file mode 100644 index 000000000..7acb6cbe4 --- /dev/null +++ b/ui/pyproject.toml @@ -0,0 +1,73 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "ui" +description = 'Minimal UI for Haystack (https://github.com/deepset-ai/haystack)' +readme = "README.md" +requires-python = ">=3.7" +license = "Apache-2.0" +keywords = [] +authors = [ + { name = "deepset.ai", email = "malte.pietsch@deepset.ai" }, +] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Science/Research", + "Topic :: Scientific/Engineering :: Artificial Intelligence", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: Implementation :: CPython", +] +dependencies = [ + "streamlit >= 1.9.0, < 2", + "st-annotated-text >= 2.0.0, < 3", + "markdown >= 3.3.4, < 4" +] +dynamic = ["version"] + +[project.urls] +Documentation = "https://github.com/deepset-ai/haystack/tree/main/ui#readme" +Issues = "https://github.com/deepset-ai/haystack/issues" +Source = "https://github.com/deepset-ai/haystack/tree/main/ui" + +[tool.hatch.version] +path = "ui/__about__.py" + +[tool.hatch.build.targets.sdist] +[tool.hatch.build.targets.wheel] + +[tool.hatch.envs.default] +dependencies = [ + "pytest", + "pytest-cov", +] +[tool.hatch.envs.default.scripts] +cov = "pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=ui --cov=tests" +no-cov = "cov --no-cov" + +[[tool.hatch.envs.test.matrix]] +python = ["37", "38", "39", "310"] + +[tool.coverage.run] +branch = true +parallel = true +omit = [ + "ui/__about__.py", +] + +[tool.coverage.report] +exclude_lines = [ + "no cov", + "if __name__ == .__main__.:", + "if TYPE_CHECKING:", +] + +[tool.black] +line-length = 120 +skip_magic_trailing_comma = true # For compatibility with pydoc>=4.6, check if still needed. diff --git a/ui/setup.py b/ui/setup.py deleted file mode 100644 index e66a7b1e1..000000000 --- a/ui/setup.py +++ /dev/null @@ -1,40 +0,0 @@ -import logging -from pathlib import Path - -from setuptools import setup, find_packages - - -VERSION = "0.0.0" -try: - # After git clone, VERSION.txt is in the root folder - VERSION = open(Path(__file__).parent.parent / "VERSION.txt", "r").read() -except Exception: - try: - # In Docker, VERSION.txt is in the same folder - VERSION = open(Path(__file__).parent / "VERSION.txt", "r").read() - except Exception as e: - logging.exception("No VERSION.txt found!") - -setup( - name="farm-haystack-ui", - version=VERSION, - description="Demo UI for Haystack (https://github.com/deepset-ai/haystack)", - author="deepset.ai", - author_email="malte.pietsch@deepset.ai", - url=" https://github.com/deepset-ai/haystack/tree/main/ui", - classifiers=[ - "Development Status :: 5 - Production/Stable", - "Intended Audience :: Science/Research", - "Topic :: Scientific/Engineering :: Artificial Intelligence", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - ], - packages=find_packages(), - python_requires=">=3.7, <4", - install_requires=["streamlit>=1.9.0, <2", "st-annotated-text>=2.0.0, <3", "markdown>=3.3.4, <4"], -) diff --git a/ui/ui/__about__.py b/ui/ui/__about__.py new file mode 100644 index 000000000..1f3b2b7c7 --- /dev/null +++ b/ui/ui/__about__.py @@ -0,0 +1,10 @@ +import logging + +from pathlib import Path + + +__version__ = "0.0.0" +try: + __version__ = open(Path(__file__).parent.parent / "VERSION.txt", "r").read() +except Exception as e: + logging.exception("No VERSION.txt found!") diff --git a/ui/__init__.py b/ui/ui/__init__.py similarity index 100% rename from ui/__init__.py rename to ui/ui/__init__.py diff --git a/ui/eval_labels_example.csv b/ui/ui/eval_labels_example.csv similarity index 100% rename from ui/eval_labels_example.csv rename to ui/ui/eval_labels_example.csv diff --git a/ui/utils.py b/ui/ui/utils.py similarity index 100% rename from ui/utils.py rename to ui/ui/utils.py diff --git a/ui/webapp.py b/ui/ui/webapp.py similarity index 100% rename from ui/webapp.py rename to ui/ui/webapp.py