Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ui and rest proper packages #2098

Merged
merged 9 commits into from
Feb 2, 2022
Merged
2 changes: 1 addition & 1 deletion .github/workflows/generate_openapi_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install .[rest]
python -m pip install rest_api/

# Generates the docstrings and tutorials so that we have the latest for the deployment
- name: Generate Docstrings and Tutorials
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/linux_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ jobs:
# that the code changes to Haystack are not being cached along with the dependencies.
# TODO for the tests refactoring: We could speed up the process by caching only
# the dependencies and installing Haystack again separately for each test runner.
key: linux-${{ hashFiles('**/*.py') }}-${{ hashFiles('setup.cfg') }}-${{ hashFiles('pyproject.toml') }}
key: linux-${{ hashFiles('**/*.py') }}-${{ hashFiles('**/setup.cfg') }}-${{ hashFiles('**/pyproject.toml') }}-${{ hashFiles('.github') }}

- name: Install dependencies
if: steps.cache-python-env.outputs.cache-hit != 'true'
run: |
pip install --upgrade pip
pip install --upgrade --upgrade-strategy eager .[test]
pip install --upgrade --upgrade-strategy eager rest_api/
pip install --upgrade --upgrade-strategy eager ui/
pip install torch-scatter -f https://data.pyg.org/whl/torch-1.10.0+cpu.html

prepare-build:
Expand Down Expand Up @@ -77,7 +79,7 @@ jobs:
uses: actions/cache@v2
with:
path: ${{ env.pythonLocation }}
key: linux-${{ hashFiles('**/*.py') }}-${{ hashFiles('setup.cfg') }}-${{ hashFiles('pyproject.toml') }}
key: linux-${{ hashFiles('**/*.py') }}-${{ hashFiles('**/setup.cfg') }}-${{ hashFiles('**/pyproject.toml') }}-${{ hashFiles('.github') }}

- name: Run Elasticsearch
run: docker run -d -p 9200:9200 -e "discovery.type=single-node" -e "ES_JAVA_OPTS=-Xms128m -Xmx128m" elasticsearch:7.9.2
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/windows_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
# that the code changes to Haystack are not being cached along with the dependencies.
# TODO for the tests refactoring: We could speed up the process by caching only
# the dependencies and installing Haystack again separately for each test runner.
key: windows-${{ hashFiles('**/*.py') }}-${{ hashFiles('setup.cfg') }}-${{ hashFiles('pyproject.toml') }}
key: windows-${{ hashFiles('**/*.py') }}-${{ hashFiles('**/setup.cfg') }}-${{ hashFiles('**/pyproject.toml') }}-${{ hashFiles('.github') }}

- name: Install Pytorch on windows
run: |
Expand All @@ -50,6 +50,8 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install --upgrade --upgrade-strategy eager .[test]
pip install --upgrade --upgrade-strategy eager rest_api/
pip install --upgrade --upgrade-strategy eager ui/
pip install torch-scatter -f https://data.pyg.org/whl/torch-1.10.0+cpu.html

prepare-build:
Expand Down Expand Up @@ -82,7 +84,7 @@ jobs:
uses: actions/cache@v2
with:
path: ${{ env.pythonLocation }}
key: windows-${{ hashFiles('**/*.py') }}-${{ hashFiles('setup.cfg') }}-${{ hashFiles('pyproject.toml') }}
key: windows-${{ hashFiles('**/*.py') }}-${{ hashFiles('**/setup.cfg') }}-${{ hashFiles('**/pyproject.toml') }}-${{ hashFiles('.github') }}

# Windows runner can't run Linux containers. Refer https://github.com/actions/virtual-environments/issues/1143
- name: Set up Windows test env
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ COPY rest_api /home/user/rest_api

# Install package
RUN pip install --upgrade pip
RUN pip install --no-cache-dir .[docstores,crawler,preprocessing,ocr,ray,rest]
RUN pip install --no-cache-dir .[docstores,crawler,preprocessing,ocr,ray]
RUN pip install --no-cache-dir rest_api/
RUN ls /home/user
RUN pip freeze
RUN python3 -c "from haystack.utils.docker import cache_models;cache_models()"
Expand Down
44 changes: 44 additions & 0 deletions rest_api/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from setuptools import setup, find_packages
import logging
from pathlib import Path


VERSION = None
try:
VERSION = open(Path(__file__).parent.parent/'VERSION.txt', "r").read()
except Exception as e:
logging.exception("No VERSION.txt found!", e)


setup(
name="farm-haystack-rest-api",
version=VERSION,
description='Demo REST API server 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/master/rest_api',
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=[
# The link below cannot be translated properly into setup.cfg
# because it looks into the parent folder.
# TODO check if this is still a limitation later on
f"farm-haystack @ file://localhost/{Path(__file__).parent.parent}#egg=farm-haystack",
"fastapi<1",
"uvicorn<1",
"gunicorn<21",
"python-multipart<1" # optional FastAPI dependency for form data
],
)
17 changes: 4 additions & 13 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ classifiers =

[options]
use_scm_version = True
python_requires = >=3.7
python_requires = >=3.7, <4
packages = find:
setup_requires =
setuptools
Expand Down Expand Up @@ -150,15 +150,6 @@ ray =
ray>=1.9.1
colab =
grpcio==1.43.0
rest =
fastapi
uvicorn
gunicorn
python-multipart # optional FastAPI dependency for form data
ui =
streamlit>=1.2.0
st-annotated-text==2.0.0
markdown>=3.3.4
dev =
mypy
pytest
Expand All @@ -170,11 +161,11 @@ dev =
pylint
black
test =
farm-haystack[docstores,crawler,preprocessing,ocr,ray,rest,ui,dev]
farm-haystack[docstores,crawler,preprocessing,ocr,ray,dev]
all =
farm-haystack[docstores,crawler,preprocessing,ocr,ray,rest,ui,dev,onnx]
farm-haystack[docstores,crawler,preprocessing,ocr,ray,dev,onnx]
all-gpu =
farm-haystack[docstores-gpu,crawler,preprocessing,ocr,ray,rest,ui,dev,onnx-gpu]
farm-haystack[docstores-gpu,crawler,preprocessing,ocr,ray,dev,onnx-gpu]


[tool:pytest]
Expand Down
8 changes: 4 additions & 4 deletions ui/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ WORKDIR /home/user

RUN apt-get update && apt-get install -y curl git pkg-config cmake

# install as a package
COPY requirements.txt /home/user/
RUN pip install -r requirements.txt

# copy code
COPY setup.py /home/user/
COPY utils.py /home/user/
COPY webapp.py /home/user/
COPY eval_labels_example.csv /home/user/

# install as a package
RUN pip install .

EXPOSE 8501

# cmd for running the API
Expand Down
43 changes: 43 additions & 0 deletions ui/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from setuptools import setup, find_packages
import logging
from pathlib import Path


VERSION = None
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!", e)

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/master/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.2.0, <2',
'st-annotated-text>=2.0.0, <3',
'markdown>=3.3.4, <4'
]
)