feat: update
Browse files- .idea/misc.xml +1 -1
- .idea/trocr-handwritten-mathematical-expressions.iml +1 -1
- README.md +47 -0
- app.py +42 -0
- canvas.png +0 -0
- requirements.txt +6 -5
- services/__init__.py +2 -0
- services/ocr.py +20 -0
- services/solver.py +15 -0
.idea/misc.xml
CHANGED
@@ -3,5 +3,5 @@
|
|
3 |
<component name="Black">
|
4 |
<option name="sdkName" value="Python 3.10 (Задачи на семинар 8. Ответы)" />
|
5 |
</component>
|
6 |
-
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.
|
7 |
</project>
|
|
|
3 |
<component name="Black">
|
4 |
<option name="sdkName" value="Python 3.10 (Задачи на семинар 8. Ответы)" />
|
5 |
</component>
|
6 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (trocr-handwritten-mathematical-expressions)" project-jdk-type="Python SDK" />
|
7 |
</project>
|
.idea/trocr-handwritten-mathematical-expressions.iml
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
<content url="file://$MODULE_DIR$">
|
5 |
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
6 |
</content>
|
7 |
-
<orderEntry type="jdk" jdkName="Python 3.
|
8 |
<orderEntry type="sourceFolder" forTests="false" />
|
9 |
</component>
|
10 |
</module>
|
|
|
4 |
<content url="file://$MODULE_DIR$">
|
5 |
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
6 |
</content>
|
7 |
+
<orderEntry type="jdk" jdkName="Python 3.10 (trocr-handwritten-mathematical-expressions)" jdkType="Python SDK" />
|
8 |
<orderEntry type="sourceFolder" forTests="false" />
|
9 |
</component>
|
10 |
</module>
|
README.md
CHANGED
@@ -1,3 +1,50 @@
|
|
1 |
---
|
2 |
license: cc-by-nc-4.0
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: cc-by-nc-4.0
|
3 |
---
|
4 |
+
|
5 |
+
# Калькулятор комплексных чисел
|
6 |
+
|
7 |
+
Позволяет решать математические задачи, написанные от руки, с помощью оптического распознавания символов (OCR) и
|
8 |
+
преобразования их в текст для последующего решения с использованием модели 🤗Transformers.
|
9 |
+
|
10 |
+
## Начало работы
|
11 |
+
|
12 |
+
Эти инструкции помогут вам запустить копию проекта на вашем локальном компьютере для тестирования. Следуйте этим
|
13 |
+
простым шагам:
|
14 |
+
|
15 |
+
### Установка Python
|
16 |
+
|
17 |
+
Если у вас еще не установлен Python 3.10, перейдите на официальный сайт Python (https://www.python.org/) и скачайте
|
18 |
+
соответствующую версию. Установите Python, следуя инструкциям на экране.
|
19 |
+
Убедитесь, что вы отметили опцию "Add Python 3.10 to PATH" во время установки.
|
20 |
+
|
21 |
+
### Клонирование репозитория
|
22 |
+
|
23 |
+
Откройте командную строку (CMD или PowerShell) и выполните следующую команду для клонирования репозитория:
|
24 |
+
|
25 |
+
```bash
|
26 |
+
git clone https://huggingface.co/MarkK/trocr-handwritten-mathematical-expressions.git
|
27 |
+
```
|
28 |
+
|
29 |
+
### Установка зависимостей
|
30 |
+
|
31 |
+
Перейдите в папку проекта с помощью команды `cd` в командной строке. Затем установите необходимые библиотеки, используя следующую команду:
|
32 |
+
|
33 |
+
```bash
|
34 |
+
pip install -r requirements.txt
|
35 |
+
```
|
36 |
+
|
37 |
+
### Запуск
|
38 |
+
|
39 |
+
После установки всех зависимостей вы можете запустить проект, используя следующую команду:
|
40 |
+
|
41 |
+
```bash
|
42 |
+
python app.py
|
43 |
+
```
|
44 |
+
|
45 |
+
@article{yu2023metamath,
|
46 |
+
title={MetaMath: Bootstrap Your Own Mathematical Questions for Large Language Models},
|
47 |
+
author={Yu, Longhui and Jiang, Weisen and Shi, Han and Yu, Jincheng and Liu, Zhengying and Zhang, Yu and Kwok, James T and Li, Zhenguo and Weller, Adrian and Liu, Weiyang},
|
48 |
+
journal={arXiv preprint arXiv:2309.12284},
|
49 |
+
year={2023}
|
50 |
+
}
|
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from services import ocr_with_paddle, solve_with_transformers
|
3 |
+
|
4 |
+
|
5 |
+
def solve_math(img):
|
6 |
+
"""
|
7 |
+
Perform optical character recognition on the input image and then solve the extracted text using 🤗transformers.
|
8 |
+
|
9 |
+
:param img: The input image for optical character recognition.
|
10 |
+
:return: The solved text answer.
|
11 |
+
"""
|
12 |
+
try:
|
13 |
+
text_output = ocr_with_paddle(img['composite'])
|
14 |
+
text_answer = solve_with_transformers(text_output)
|
15 |
+
|
16 |
+
return text_answer
|
17 |
+
except Exception:
|
18 |
+
raise gr.Error("Please upload an image!!!!")
|
19 |
+
|
20 |
+
|
21 |
+
"""
|
22 |
+
Create user interface
|
23 |
+
"""
|
24 |
+
|
25 |
+
|
26 |
+
def main():
|
27 |
+
with gr.Blocks() as app:
|
28 |
+
gr.Markdown("### Калькулятор комплексных чисел")
|
29 |
+
with gr.Row():
|
30 |
+
with gr.Column():
|
31 |
+
image_input = gr.ImageEditor(value='canvas.png', image_mode='L', interactive=True, type='filepath')
|
32 |
+
process_btn = gr.Button('Решить')
|
33 |
+
with gr.Column():
|
34 |
+
output_text = gr.Textbox(label="Решение")
|
35 |
+
|
36 |
+
process_btn.click(fn=solve_math, inputs=image_input, outputs=output_text)
|
37 |
+
|
38 |
+
app.launch()
|
39 |
+
|
40 |
+
|
41 |
+
if __name__ == "__main__":
|
42 |
+
main()
|
canvas.png
ADDED
requirements.txt
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
|
|
|
|
5 |
scikit-learn~=1.4.1.post1
|
6 |
-
accelerate
|
7 |
requests~=2.31.0
|
|
|
1 |
+
gradio~=4.19.2
|
2 |
+
paddleocr~=2.7.0.3
|
3 |
+
transformers~=4.35.2
|
4 |
+
pandas~=2.1.3
|
5 |
+
torch~=2.1.1
|
6 |
+
Pillow~=10.1.0
|
7 |
scikit-learn~=1.4.1.post1
|
|
|
8 |
requests~=2.31.0
|
services/__init__.py
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
from .ocr import ocr_with_paddle
|
2 |
+
from .solver import solve_with_transformers
|
services/ocr.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from paddleocr import PaddleOCR
|
2 |
+
|
3 |
+
|
4 |
+
def ocr_with_paddle(img):
|
5 |
+
"""
|
6 |
+
Perform Optical Character Recognition (OCR) on the input image.
|
7 |
+
|
8 |
+
:param img: The input image for OCR
|
9 |
+
:return: The recognized text from the input image, or 'No text detected' if no text is found
|
10 |
+
"""
|
11 |
+
finaltext = ''
|
12 |
+
ocr = PaddleOCR(lang='en', use_angle_cls=True)
|
13 |
+
result = ocr.ocr(img)
|
14 |
+
try:
|
15 |
+
for i in range(len(result[0])):
|
16 |
+
text = result[0][i][1][0]
|
17 |
+
finaltext += ' ' + text
|
18 |
+
return finaltext
|
19 |
+
except TypeError:
|
20 |
+
return 'No text detected'
|
services/solver.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Use a 🤗pipeline as a high-level helper
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
|
5 |
+
def solve_with_transformers(text):
|
6 |
+
"""
|
7 |
+
Solve the given text using 🤗transformers
|
8 |
+
|
9 |
+
:param text: The text to solve
|
10 |
+
:return: The solved text
|
11 |
+
"""
|
12 |
+
pipe = pipeline("text-generation", model="meta-math/MetaMath-Mistral-7B")
|
13 |
+
answer = pipe(text)
|
14 |
+
|
15 |
+
return answer
|