Skip to content

Commit

Permalink
Merge pull request #143 from lukas-blecher/docker-api
Browse files Browse the repository at this point in the history
Add docker image for API
  • Loading branch information
lukas-blecher authored May 3, 2022
2 parents 0ac47cb + a228514 commit 4172b0b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@ There are three ways to get a prediction from an image.
```bash
python -m pix2tex.api.run
```
to start a [Streamlit](https://streamlit.io/) demo that connects to the API at port 8502.
to start a [Streamlit](https://streamlit.io/) demo that connects to the API at port 8502. There is also a docker image available for the API: https://hub.docker.com/r/lukasblecher/pix2tex

```
docker pull lukasblecher/pix2tex:api
docker run -p 8502:8502 lukasblecher/pix2tex:api
```
To also run the streamlit demo run
```
docker run -it -p 8501:8501 --entrypoint python lukasblecher/pix2tex:api pix2tex/api/run.py
```
and navigate to http://localhost:8501/

The model works best with images of smaller resolution. That's why I added a preprocessing step where another neural network predicts the optimal resolution of the input image. This model will automatically resize the custom image to best resemble the training data and thus increase performance of images found in the wild. Still it's not perfect and might not be able to handle huge images optimally, so don't zoom in all the way before taking a picture.
Expand Down
10 changes: 10 additions & 0 deletions docker/api.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3.8-slim
RUN pip install torch>=1.7.1
WORKDIR /latexocr
ADD pix2tex /latexocr/pix2tex/
ADD setup.py /latexocr/
ADD README.md /latexocr/
RUN pip install -e .[api]
RUN python -m pix2tex.model.checkpoints.get_latest_checkpoint

ENTRYPOINT ["uvicorn", "pix2tex.api.app:app", "--host", "0.0.0.0", "--port", "8502"]
4 changes: 4 additions & 0 deletions docker/build-api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# cd into proj. root
cd $(dirname $0)
cd ..
docker build -t lukasblecher/pix2tex:api -f docker/api.dockerfile .
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

setuptools.setup(
name='pix2tex',
version='0.0.23',
version='0.0.24',
description='pix2tex: Using a ViT to convert images of equations into LaTeX code.',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down

0 comments on commit 4172b0b

Please sign in to comment.