Skip to content

Commit 4172b0b

Browse files
Merge pull request #143 from lukas-blecher/docker-api
Add docker image for API
2 parents 0ac47cb + a228514 commit 4172b0b

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,17 @@ There are three ways to get a prediction from an image.
3434
```bash
3535
python -m pix2tex.api.run
3636
```
37-
to start a [Streamlit](https://streamlit.io/) demo that connects to the API at port 8502.
37+
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
38+
39+
```
40+
docker pull lukasblecher/pix2tex:api
41+
docker run -p 8502:8502 lukasblecher/pix2tex:api
42+
```
43+
To also run the streamlit demo run
44+
```
45+
docker run -it -p 8501:8501 --entrypoint python lukasblecher/pix2tex:api pix2tex/api/run.py
46+
```
47+
and navigate to http://localhost:8501/
3848

3949
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.
4050

docker/api.dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM python:3.8-slim
2+
RUN pip install torch>=1.7.1
3+
WORKDIR /latexocr
4+
ADD pix2tex /latexocr/pix2tex/
5+
ADD setup.py /latexocr/
6+
ADD README.md /latexocr/
7+
RUN pip install -e .[api]
8+
RUN python -m pix2tex.model.checkpoints.get_latest_checkpoint
9+
10+
ENTRYPOINT ["uvicorn", "pix2tex.api.app:app", "--host", "0.0.0.0", "--port", "8502"]

docker/build-api.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# cd into proj. root
2+
cd $(dirname $0)
3+
cd ..
4+
docker build -t lukasblecher/pix2tex:api -f docker/api.dockerfile .

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
setuptools.setup(
2929
name='pix2tex',
30-
version='0.0.23',
30+
version='0.0.24',
3131
description='pix2tex: Using a ViT to convert images of equations into LaTeX code.',
3232
long_description=long_description,
3333
long_description_content_type='text/markdown',

0 commit comments

Comments
 (0)