Skip to content

Commit 56edd9c

Browse files
committed
change api port, add to readme
1 parent 084fb03 commit 56edd9c

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,22 @@ pip install pix2tex[gui]
1717

1818
Model checkpoints will be downloaded automatically.
1919

20-
There are two ways to get a prediction from an image.
20+
There are three ways to get a prediction from an image.
2121
1. You can use the command line tool by calling `pix2tex`. Here you can parse already existing images from the disk and images in your clipboard.
2222

2323
2. Thanks to [@katie-lim](https://github.com/katie-lim), you can use a nice user interface as a quick way to get the model prediction. Just call the GUI with `latexocr`. From here you can take a screenshot and the predicted latex code is rendered using [MathJax](https://www.mathjax.org/) and copied to your clipboard.
2424

2525
Under linux, it is possible to use the GUI with `gnome-screenshot` which comes with multiple monitor support. You just need to run `latexocr --gnome` (**Note:** you should install `gnome-screenshot` beforehand).
2626

27-
![demo](https://user-images.githubusercontent.com/55287601/117812740-77b7b780-b262-11eb-81f6-fc19766ae2ae.gif)
27+
![demo](https://user-images.githubusercontent.com/55287601/117812740-77b7b780-b262-11eb-81f6-fc19766ae2ae.gif)
2828

29-
If the model is unsure about the what's in the image it might output a different prediction every time you click "Retry". With the `temperature` parameter you can control this behavior (low temperature will produce the same result).
29+
If the model is unsure about the what's in the image it might output a different prediction every time you click "Retry". With the `temperature` parameter you can control this behavior (low temperature will produce the same result).
3030

31+
3. You can use an API. This has additional dependencies. Install via `pip install -U pix2tex[api]` and run
32+
```bash
33+
python -m pix2tex.api.run
34+
```
35+
to start a [Streamlit](https://streamlit.io/) demo that connects to the API at port 8502.
3136

3237
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.
3338

pix2tex/api/app.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Adapted from https://github.com/kingyiusuen/image-to-latex/blob/main/api/app.py
22

3-
from ctypes import resize
43
from http import HTTPStatus
54
from fastapi import FastAPI, File, UploadFile, Form
65
from PIL import Image

pix2tex/api/run.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
def start_api(path='.'):
7-
subprocess.call(['uvicorn', 'app:app'], cwd=path)
7+
subprocess.call(['uvicorn', 'app:app', '--port', '8502'], cwd=path)
88

99

1010
def start_frontend(path='.'):

pix2tex/api/streamlit.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
if streamlit.button('Convert'):
2323
if uploaded_file is not None and image is not None:
2424
with streamlit.spinner('Computing'):
25-
response = requests.post('http://127.0.0.1:8000/predict/', files={'file': uploaded_file.getvalue()})
25+
response = requests.post('http://127.0.0.1:8502/predict/', files={'file': uploaded_file.getvalue()})
2626
if response.ok:
2727
latex_code = response.json()
2828
streamlit.code(latex_code, language='latex')

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
setuptools.setup(
2424
name='pix2tex',
25-
version='0.0.21',
25+
version='0.0.22',
2626
description='pix2tex: Using a ViT to convert images of equations into LaTeX code.',
2727
long_description=long_description,
2828
long_description_content_type='text/markdown',

0 commit comments

Comments
 (0)