hasibzunair commited on
Commit
d2f8dba
β€’
1 Parent(s): 546b390
Files changed (6) hide show
  1. README.md +1 -1
  2. app.py +39 -0
  3. eqn1.png +0 -0
  4. eqn2.png +0 -0
  5. eqn3.png +0 -0
  6. requirements.txt +3 -0
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
  title: LaTeX OCR Demo
3
- emoji: πŸ“š
4
  colorFrom: indigo
5
  colorTo: indigo
6
  sdk: gradio
 
1
  ---
2
  title: LaTeX OCR Demo
3
+ emoji: πŸ“šβœ–οΈβž• πŸ”’
4
  colorFrom: indigo
5
  colorTo: indigo
6
  sdk: gradio
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import PIL
3
+ import gradio as gr
4
+ from PIL import Image
5
+
6
+ os.system("pip install pix2tex")
7
+ os.system("pip install opencv-python-headless==4.1.2.30")
8
+
9
+ # Load model
10
+ from pix2tex import cli as pix2tex
11
+
12
+ model = pix2tex.LatexOCR()
13
+
14
+
15
+ def inference(input_image_path):
16
+ img = Image.open(input_image_path)
17
+ output = model(img)
18
+ print("Model output:",output)
19
+ return output
20
+
21
+
22
+ # Front end
23
+ title = "Convert images of equations into LaTeX code πŸ“šβœ–οΈβž• πŸ”’"
24
+ 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>"
25
+ 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>"
26
+
27
+
28
+ # UI
29
+ gr.Interface(
30
+ inference,
31
+ title=title,
32
+ description=description,
33
+ article=article,
34
+ inputs=gr.inputs.Image(type="filepath", label="Input: Image of your equation you want to covert."),
35
+ outputs=gr.outputs.Textbox(type="text", label="Output: Converted LaTeX code."),
36
+ examples=["./eqn1.png", "./eqn2.png", "./eqn3.png"],
37
+ allow_flagging="never",
38
+ analytics_enabled=False,
39
+ ).launch()
eqn1.png ADDED
eqn2.png ADDED
eqn3.png ADDED
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ torch
2
+ torchvision
3
+ Pillow