Skip to content

Commit

Permalink
Merge pull request #16 from KSUSeniorProject-MathLearningMachine/remo…
Browse files Browse the repository at this point in the history
…ve-mathpix

Remove all mathpix
  • Loading branch information
kemp authored Nov 19, 2020
2 parents e14e040 + 868047a commit e517350
Show file tree
Hide file tree
Showing 9 changed files with 2 additions and 116 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Update the environment files
run: |
echo "MATHPIX_APP_KEY=${{ secrets.MATHPIX_APP_KEY }}" >> mathpix-variables.env
echo "MATHPIX_APP_ID=${{ secrets.MATHPIX_APP_ID }}" >> mathpix-variables.env
- name: Build the Docker image
run: |
docker-compose build
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ __pycache__
.pytest_cache
flaskenv/
.idea/
mathpix-variables.env
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
version: '2.0'
services:
flask:
env_file:
- "mathpix-variables.env"
build: .
image: mathlm:latest
ports:
Expand Down
2 changes: 0 additions & 2 deletions docs/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@ For better performance on Windows, install [Windows Subsystem for Linux 2](https

The Dockerfile in this repo configures the image environment for our app. Docker-Compose is used as a simple way to do cross-platform building. It reduces the number of commands that have to be run manually, while avoiding platform-dependent bash or batch scripts.

**NOTE:** Before building or running the image, it is necessary to create the enviornment file, which contains private API keys. An [example file](/mathpix-variables.env.example) is provided with instructions.

Run `docker-compose build` to build the image, including code changes.
Run `docker-compose run --entrypoint bash flask` to launch the container and drop into a shell for development.
32 changes: 0 additions & 32 deletions flask/flaskapp/flaskapp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import mathpix
import latex_solver
import detector
import object_parser
Expand Down Expand Up @@ -40,37 +39,6 @@ def ocr():
}


@app.route('/mathpix-ocr', methods=['POST'])
@cross_origin()
def mathpix_ocr():
img = request.get_json()['b64_img']

try:
return mathpix.submit_text(img)
except mathpix.MathpixApiException as e:
return e, 500


@app.route('/solve-image-mathpix', methods=['POST'])
@cross_origin()
def solve_image_mathpix():
body = request.get_json()

try:
response = mathpix.submit_text(body['b64_img'])
latex_styled = response['latex_styled']

data = {
'solved': latex_solver.solve(latex_styled),
'input_detected': latex_solver.format_latex(latex_styled),
'confidence': response['confidence']
}

return data, 200
except mathpix.MathpixApiException as e:
return e, 500


@app.route('/solve-image', methods=['POST'])
@cross_origin()
def solve_image():
Expand Down
22 changes: 0 additions & 22 deletions flask/flaskapp/mathpix.py

This file was deleted.

19 changes: 0 additions & 19 deletions flask/flaskapp/tests/test_flaskapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,6 @@ def test_home_page(client, app):
assert b'Hello, World!' == res.data


def test_mathpix_ocr(client, app):
with open('tests/imagetest.txt', 'r') as file:
image = file.read().replace('\n', '')

response_schema = {
"type": "object",
"properties": {
"confidence": {"type": "number"},
"latex_styled": {"type": "string"},
"request_id": {"type": "string"},
},
}
res = client.post('/mathpix-ocr', json={
'b64_img': image
})

assert True == validate_json(instance=res.get_json(), schema=response_schema)


def test_solve_image(client, app):
with open('tests/imagetest.txt', 'r') as file:
image = file.read().replace('\n', '')
Expand Down
7 changes: 0 additions & 7 deletions mathpix-variables.env.example

This file was deleted.

29 changes: 2 additions & 27 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ To run the tests:
**Response Body**:

{
"confidence": (number) CONFIDENCE_VALUE_FROM_MATHPIX,
"input_detected": (str) "LATEX_STRING_OF_INPUT_DETECTED_FROM_MATHPIX",
"confidence": (number) CONFIDENCE_VALUE,
"input_detected": (str) "LATEX_STRING_OF_INPUT_DETECTED",
"solved": (str) "LATEX_STRING_OF_CAS_SOLUTION_TO_PROBLEM"
}

Expand All @@ -84,28 +84,3 @@ To run the tests:
{
"solved": (str) "LATEX_STRING_OF_CAS_SOLUTION_TO_PROBLEM"
}

### Mathpix OCR

**URI**: `/mathpix-ocr`

**Method**: POST

**Request Body**:

{
"b64_img":(str)"BASEBASE64ENCODEDIMAGE"
}

**Response Body**:

{
"confidence":(number) CONFIDENCE_VALUE_FROM_MATPHIX,
"confidence_rate":(number) CONFIDENCE_RATE_FROM_MATHPIX,
"latex_styled":(str) "LATEX_STRING_OF_INPUT_DETECTED_FROM_MATHPIX",
"request_id":(str) Doesn't mean anything to us,
"text":(str) Doesnt mean much as we are using latex
}



0 comments on commit e517350

Please sign in to comment.