import requests from PIL import Image from pix2tex.cli import LatexOCR from PIL import Image 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.\n\nThis 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)" ) 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(uploaded_file.getvalue()) try: result = model(image) streamlit.code(result, language="latex") streamlit.markdown(f"$\\displaystyle {result}$") except Exception as e: streamlit.error(e) else: streamlit.error("Please upload an image.")