Spaces:
Runtime error
Runtime error
import os | |
import PIL | |
import gradio as gr | |
from PIL import Image | |
os.system("pip install pix2tex") | |
os.system("pip install opencv-python-headless==4.1.2.30") | |
# Load model | |
from pix2tex import cli as pix2tex | |
model = pix2tex.LatexOCR() | |
def inference(input_image_path): | |
img = Image.open(input_image_path) | |
output = model(img) | |
print("Model output:",output) | |
return output | |
# Front end | |
title = "Convert images of equations into LaTeX code πβοΈβ π’" | |
description = "<div> Did you come across a complex mathematical expression that you want to refer to in your report/thesis? Is your freemium over at <a href='https://mathpix.com/' target='_blank'>Mathpix</a>? π« <br><br> Take a screenshot of the equation and use this application to convert it into LaTeX code. π To use it, simply upload your screenshot/equation image, or click one of the examples to load them. To verify the results, copy & paste the output in <a href='https://quicklatex.com/' target='_blank'>Quick LaTeX</a>. Read more at the links below.</div>" | |
article = "<p style='text-align: center'><a href='https://lukas-blecher.github.io/LaTeX-OCR/' target='_blank'>pix2tex: Using a ViT to convert images of equations into LaTeX code</a> | <a href='https://github.com/lukas-blecher/LaTeX-OCR' target='_blank'>Github</a></p>" | |
# UI | |
gr.Interface( | |
inference, | |
title=title, | |
description=description, | |
article=article, | |
inputs=gr.inputs.Image(type="filepath", label="Input: Image of your equation you want to covert."), | |
outputs=gr.outputs.Textbox(type="text", label="Output: Converted LaTeX code."), | |
examples=["./eqn1.png", "./eqn2.png", "./eqn3.png"], | |
allow_flagging="never", | |
analytics_enabled=False, | |
).launch() | |