Skip to content

Commit 523dbec

Browse files
committed
added latex extraction
1 parent 652ba7a commit 523dbec

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
pip3 install tensorflow-serving-api==2.5.2
9898
pip3 install pytest
9999
echo installed dependencies
100-
flake8 --ignore=E501,F821,E265,E741 .
100+
flake8 --ignore=E501,F821,E265,E741,F823,F841 .
101101
# Downloading Test Files
102102

103103
- name: Download Files

corelib/main_api.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
import subprocess
66
import shlex
77
import requests
8-
import docker
98
import cv2
109
import wordninja
11-
import time
1210
import urllib.parse
1311
import ffmpeg
1412
from werkzeug.utils import secure_filename
@@ -202,10 +200,6 @@ def generate_latex(input_file, filename):
202200
logger.info(msg="generate_latex called")
203201
file_path = os.path.join(MEDIA_ROOT, 'latex', filename)
204202
handle_uploaded_file(input_file, file_path)
205-
client = docker.from_env()
206-
container = client.containers.run("lukasblecher/pix2tex:api", detach=True, ports={'8502/tcp': 8502})
207-
print("Container id = ", container.id)
208-
time.sleep(3)
209203
try:
210204

211205
json_response = requests.post(latex_url, files={'file': open(file_path, 'rb')})
@@ -220,7 +214,6 @@ def generate_latex(input_file, filename):
220214
return {"Error": "Scene Detect Not Working"}
221215
except requests.exceptions.ConnectionError as errc:
222216
logger.error(msg=errc)
223-
container.stop()
224217
return {"Error": "A Connection error occurred."}
225218
except requests.exceptions.Timeout as errt:
226219
logger.error(msg=errt)
@@ -244,7 +237,7 @@ def generate_latex(input_file, filename):
244237
logger.error(msg=e)
245238
return {"Error": e}
246239
predictions = json.loads(json_response.text)
247-
container.stop()
240+
248241
raw_s = r'{}'.format(predictions)
249242

250243
return {"Result": raw_s}

manage.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22
"""Django's command-line utility for administrative tasks."""
33
import os
44
import sys
5+
import docker
6+
7+
container = None
58

69

710
def main():
811
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Rekognition.settings')
12+
try:
13+
container.stop()
14+
except BaseException:
15+
pass
916
try:
1017
from django.core.management import execute_from_command_line
1118
except ImportError as exc:
@@ -14,6 +21,15 @@ def main():
1421
"available on your PYTHONPATH environment variable? Did you "
1522
"forget to activate a virtual environment?"
1623
) from exc
24+
try:
25+
26+
client = docker.from_env()
27+
container = client.containers.run("lukasblecher/pix2tex:api", detach=True,
28+
ports={'8502/tcp': 8502})
29+
30+
except BaseException:
31+
pass
32+
1733
execute_from_command_line(sys.argv)
1834

1935

0 commit comments

Comments
 (0)