Lukas Blecher commited on
Commit
c89b433
1 Parent(s): 44b8827
Files changed (2) hide show
  1. app.py +10 -8
  2. requirements.txt +1 -0
app.py CHANGED
@@ -2,8 +2,11 @@ import os
2
  from PIL import Image
3
  import streamlit
4
  from pix2tex.cli import LatexOCR
 
5
 
6
- args = {'checkpoint': os.path.realpath(os.path.join(os.path.dirname(__file__), 'checkpoints/weights.pth')), 'no_resize': False}
 
 
7
  model = LatexOCR(args)
8
 
9
  if __name__ == '__main__':
@@ -26,12 +29,11 @@ if __name__ == '__main__':
26
  if streamlit.button('Convert'):
27
  if uploaded_file is not None and image is not None:
28
  with streamlit.spinner('Computing'):
29
- response = model(image)
30
- if response.ok:
31
- latex_code = response.json()
32
- streamlit.code(latex_code, language='latex')
33
- streamlit.markdown(f'$\\displaystyle {latex_code}$')
34
- else:
35
- streamlit.error(response.text)
36
  else:
37
  streamlit.error('Please upload an image.')
 
2
  from PIL import Image
3
  import streamlit
4
  from pix2tex.cli import LatexOCR
5
+ from munch import Munch
6
 
7
+ args = Munch({'config': 'settings/config.yaml',
8
+ 'checkpoint': os.path.realpath(os.path.join(os.path.dirname(__file__), 'checkpoints/weights.pth')),
9
+ 'no_resize': False})
10
  model = LatexOCR(args)
11
 
12
  if __name__ == '__main__':
 
29
  if streamlit.button('Convert'):
30
  if uploaded_file is not None and image is not None:
31
  with streamlit.spinner('Computing'):
32
+ try:
33
+ latex_code = model(image)
34
+ streamlit.code(latex_code, language='latex')
35
+ streamlit.markdown(f'$\\displaystyle {latex_code}$')
36
+ except Exception as e:
37
+ streamlit.error(e)
 
38
  else:
39
  streamlit.error('Please upload an image.')
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  pix2tex
2
  streamlit
 
 
1
  pix2tex
2
  streamlit
3
+ munch