Skip to content

Commit

Permalink
Merge pull request #2 from VikParuchuri/dev
Browse files Browse the repository at this point in the history
Add usage tips, fix \big tags
  • Loading branch information
VikParuchuri authored Dec 23, 2023
2 parents 67780e5 + 75baaec commit fdc40d2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ Model weights will automatically download the first time you run it.
- Inspect the settings in `texify/settings.py`. You can override any settings with environment variables.
- Your torch device will be automatically detected, but you can override this. For example, `TORCH_DEVICE=cuda` or `TORCH_DEVICE=mps`.

## Usage tips

- Don't make your boxes too small or too large. See the examples and the video above for good crops.
- Texify is sensitive to how you draw the box around the text you want to OCR. If you get bad results, try selecting a slightly different box, or splitting the box into 2+. You can also try changing the `TEMPERATURE` setting.
- Sometimes, KaTeX won't be able to render an equation (red error), but it will still be valid LaTeX. You can copy the LaTeX and render it elsewhere.

## App for interactive conversion

I've included a streamlit app that lets you interactively select and convert equations from images or PDF files. Run it with:
Expand Down
19 changes: 16 additions & 3 deletions ocr_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@


def replace_katex_invalid(string):
return re.sub(r'\\tag\{.*?\}', '', string)
# KaTeX cannot render all LaTeX, so we need to replace some things
string = re.sub(r'\\tag\{.*?\}', '', string)
string = re.sub(r'\\Big\{(.*?)\}|\\big\{(.*?)\}', r'\1\2', string)
return string

@st.cache_resource()
def load_model_cached():
Expand Down Expand Up @@ -86,7 +89,7 @@ def get_image_size(pil_image):

top_message = """### Texify
After the model loads, upload an image or a pdf, then draw a box around the equation or text you want to OCR by clicking and dragging. Texify will convert it to Markdown with LaTeX math on the right. If you don't get good results, try selecting a slightly different box, or changing the temperature value.
After the model loads, upload an image or a pdf, then draw a box around the equation or text you want to OCR by clicking and dragging. Texify will convert it to Markdown with LaTeX math on the right.
If you have already cropped your image, select "OCR image" in the sidebar instead.
"""
Expand Down Expand Up @@ -151,4 +154,14 @@ def get_image_size(pil_image):
katex_markdown = replace_katex_invalid(inference)
st.markdown(katex_markdown)
st.code(inference)
st.divider()
st.divider()

with col2:
tips = """
### Usage tips
- Don't make your boxes too small or too large. See the examples and the video in the [README](https://github.com/vikParuchuri/texify) for more info.
- Texify is sensitive to how you draw the box around the text you want to OCR. If you get bad results, try selecting a slightly different box, or splitting the box into multiple.
- You can try changing the temperature value on the left if you don't get good results. This controls how "creative" the model is.
- Sometimes KaTeX won't be able to render an equation (red error text), but it will still be valid LaTeX. You can copy the LaTeX and render it elsewhere.
"""
st.markdown(tips)

0 comments on commit fdc40d2

Please sign in to comment.