Spaces:
Running
Running
Commit
•
d8e0bc8
1
Parent(s):
0cecc22
Upload 2 files
Browse files- app.py +38 -0
- requirements.txt +13 -0
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
from PIL import Image
|
3 |
+
import streamlit
|
4 |
+
from simple_latex_ocr.models import Latex_OCR
|
5 |
+
model=Latex_OCR()
|
6 |
+
if __name__ == '__main__':
|
7 |
+
streamlit.set_page_config(page_title='Simple-LaTeX-OCR')
|
8 |
+
streamlit.title('Simple-LaTeX-OCR')
|
9 |
+
streamlit.markdown('Convert images of equations to corresponding LaTeX code.\n\nThis is based on the `Simple-LaTeX-OCR` module. Check it out (https://github.com/chaodreaming/Simple-LaTeX-OCR)')
|
10 |
+
|
11 |
+
uploaded_file = streamlit.file_uploader(
|
12 |
+
'Upload an image an equation',
|
13 |
+
type=['png', 'jpg'],
|
14 |
+
)
|
15 |
+
|
16 |
+
if uploaded_file is not None:
|
17 |
+
image = Image.open(uploaded_file)
|
18 |
+
streamlit.image(image)
|
19 |
+
else:
|
20 |
+
streamlit.text('\n')
|
21 |
+
|
22 |
+
if streamlit.button('Convert'):
|
23 |
+
if uploaded_file is not None and image is not None:
|
24 |
+
with streamlit.spinner('Computing'):
|
25 |
+
|
26 |
+
response =model.predict(uploaded_file.getvalue())
|
27 |
+
if "formula" in response:
|
28 |
+
latex_code = response["formula"]
|
29 |
+
streamlit.code(latex_code, language='latex')
|
30 |
+
streamlit.markdown(f'$\\displaystyle {latex_code}$')
|
31 |
+
# 添加跳转按钮
|
32 |
+
streamlit.markdown(
|
33 |
+
'<a href="https://www.latexlive.com/" target="_blank"><button style="color: black;">Online Editing</button></a>',
|
34 |
+
unsafe_allow_html=True)
|
35 |
+
else:
|
36 |
+
streamlit.error(response)
|
37 |
+
else:
|
38 |
+
streamlit.error('Please upload an image.')
|
requirements.txt
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
onnxruntime-gpu
|
2 |
+
tokenizers>=0.13.2
|
3 |
+
numpy
|
4 |
+
opencv-python
|
5 |
+
Pillow>=9.2.0
|
6 |
+
PyYAML>=6.0.0
|
7 |
+
transformers
|
8 |
+
flask
|
9 |
+
fastapi
|
10 |
+
uvicorn
|
11 |
+
simple_latex_ocr
|
12 |
+
opencv-python-headless
|
13 |
+
easydict>=1.13
|