File size: 1,395 Bytes
eaf9ae6
54a9640
 
eaf9ae6
195f7e6
eaf9ae6
 
 
 
 
 
 
 
9b00e81
 
 
 
 
 
 
eaf9ae6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195f7e6
eaf9ae6
195f7e6
eaf9ae6
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import requests
from PIL import Image
from pix2tex.cli import LatexOCR
from PIL import Image
from io import BytesIO
import streamlit

model = LatexOCR()


streamlit.set_page_config(page_title="LaTeX-OCR")
streamlit.title("LaTeX OCR")
streamlit.markdown(
    """
Convert images of equations to corresponding LaTeX code.
    
This is based on the `pix2tex` module. Check it out [![github](https://img.shields.io/badge/LaTeX--OCR-visit-a?style=social&logo=github)](https://github.com/lukas-blecher/LaTeX-OCR)

--deployed by [C0MM4ND](https://github.com/c0mm4nd), code [here](https://huggingface.co/spaces/c0mm4nd/LaTeX-OCR/tree/main)
    """
)

uploaded_file = streamlit.file_uploader(
    "Upload an image an equation",
    type=["png", "jpg"],
)

if uploaded_file is not None:
    image = Image.open(uploaded_file)
    streamlit.image(image)
else:
    streamlit.text("\n")

if streamlit.button("Convert"):
    if uploaded_file is not None and image is not None:
        with streamlit.spinner("Computing"):
            image = Image.open(BytesIO(uploaded_file.getvalue()))
            try:
                result = model(image, resize=False)
                streamlit.code(result, language="latex")
                streamlit.markdown(f"$\\displaystyle {result}$")
            except Exception as e:
                streamlit.error(e)

    else:
        streamlit.error("Please upload an image.")