Skip to content

Commit 191ce2d

Browse files
authored
Merge branch 'development' into add-basic-tests
2 parents 2452a36 + 5d4208f commit 191ce2d

3 files changed

Lines changed: 78 additions & 3 deletions

File tree

flask/flaskapp/latex_solver.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
from sympy.parsing.latex import parse_latex
2+
from sympy.parsing.latex import LaTeXParsingError
23
from sympy import latex
34

45
def solve(latex_styled):
56
latex_formatted = format_latex(latex_styled)
6-
expr = parse_latex(latex_formatted)
7+
try:
8+
expr = parse_latex(latex_formatted)
9+
except LaTeXParsingError:
10+
return "LaTeX parsing error"
711

8-
return str(latex(expr.doit()))
12+
try:
13+
result = latex(expr.doit())
14+
#This is super generic because sympy evaluation isn't trivial.
15+
# We'll probably want to switch away from using doit() in the future, for more control.
16+
except Exception:
17+
return "SymPy evaluation error"
18+
return str(result)
919

1020
def format_latex(latex_styled):
1121
return r'{}'.format(latex_styled)

flask/flaskapp/mathpix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class MathpixApiException(Exception):
1212
pass
1313

1414
def submit_text(b64_image):
15-
data = { "src": "data:image/png;base64," + b64_image }
15+
data = { "src": b64_image }
1616
url = BASE_URL + "/text"
1717
response = requests.post(url, headers=HEADERS, json=data)
1818

readme.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,68 @@ To run the tests:
4444
$ docker-compose build
4545
$ docker-compose run flask bash -c "cd /app/flask/flaskapp && python -m pytest"
4646

47+
48+
## Public API
49+
50+
### Solve Image
51+
52+
**URI**: `/solve-image`
53+
54+
**Method**: POST
55+
56+
**Request Body**:
57+
58+
{
59+
"b64_img": (str) "BASE64ENCODEDIMAGE"
60+
}
61+
62+
**Response Body**:
63+
64+
{
65+
"confidence": (number) CONFIDENCE_VALUE_FROM_MATHPIX,
66+
"input_detected": (str) "LATEX_STRING_OF_INPUT_DETECTED_FROM_MATHPIX",
67+
"solved": (str) "LATEX_STRING_OF_CAS_SOLUTION_TO_PROBLEM"
68+
}
69+
70+
### Solve Latex
71+
72+
**URI**: `/solve-latex`
73+
74+
**Method**: POST
75+
76+
**Request Body**:
77+
78+
{
79+
"latex": (str) "LATEX_TO_BE_SOLVED"
80+
}
81+
82+
**Response Body**:
83+
84+
{
85+
"solved": (str) "LATEX_STRING_OF_CAS_SOLUTION_TO_PROBLEM"
86+
}
87+
88+
### Mathpix OCR
89+
90+
**URI**: `/mathpix-ocr`
91+
92+
**Method**: POST
93+
94+
**Request Body**:
95+
96+
{
97+
"b64_img":(str)"BASEBASE64ENCODEDIMAGE"
98+
}
99+
100+
**Response Body**:
101+
102+
{
103+
"confidence":(number) CONFIDENCE_VALUE_FROM_MATPHIX,
104+
"confidence_rate":(number) CONFIDENCE_RATE_FROM_MATHPIX,
105+
"latex_styled":(str) "LATEX_STRING_OF_INPUT_DETECTED_FROM_MATHPIX",
106+
"request_id":(str) Doesn't mean anything to us,
107+
"text":(str) Doesnt mean much as we are using latex
108+
}
109+
110+
111+

0 commit comments

Comments
 (0)