kshipra-jadav commited on
Commit
029be91
·
1 Parent(s): c7b676d

flask test

Browse files
Files changed (4) hide show
  1. .gitignore +172 -0
  2. Dockerfile +11 -0
  3. app.py +38 -0
  4. requirements.txt +60 -0
.gitignore ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Created by https://www.toptal.com/developers/gitignore/api/flask
2
+ # Edit at https://www.toptal.com/developers/gitignore?templates=flask
3
+
4
+ ### Flask ###
5
+ instance/*
6
+ !instance/.gitignore
7
+ .webassets-cache
8
+ .env
9
+
10
+ ### Flask.Python Stack ###
11
+ # Byte-compiled / optimized / DLL files
12
+ __pycache__/
13
+ *.py[cod]
14
+ *$py.class
15
+
16
+ # C extensions
17
+ *.so
18
+
19
+ # Distribution / packaging
20
+ .Python
21
+ build/
22
+ develop-eggs/
23
+ dist/
24
+ downloads/
25
+ eggs/
26
+ .eggs/
27
+ lib/
28
+ lib64/
29
+ parts/
30
+ sdist/
31
+ var/
32
+ wheels/
33
+ share/python-wheels/
34
+ *.egg-info/
35
+ .installed.cfg
36
+ *.egg
37
+ MANIFEST
38
+
39
+ # PyInstaller
40
+ # Usually these files are written by a python script from a template
41
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
42
+ *.manifest
43
+ *.spec
44
+
45
+ # Installer logs
46
+ pip-log.txt
47
+ pip-delete-this-directory.txt
48
+
49
+ # Unit test / coverage reports
50
+ htmlcov/
51
+ .tox/
52
+ .nox/
53
+ .coverage
54
+ .coverage.*
55
+ .cache
56
+ nosetests.xml
57
+ coverage.xml
58
+ *.cover
59
+ *.py,cover
60
+ .hypothesis/
61
+ .pytest_cache/
62
+ cover/
63
+
64
+ # Translations
65
+ *.mo
66
+ *.pot
67
+
68
+ # Django stuff:
69
+ *.log
70
+ local_settings.py
71
+ db.sqlite3
72
+ db.sqlite3-journal
73
+
74
+ # Flask stuff:
75
+ instance/
76
+
77
+ # Scrapy stuff:
78
+ .scrapy
79
+
80
+ # Sphinx documentation
81
+ docs/_build/
82
+
83
+ # PyBuilder
84
+ .pybuilder/
85
+ target/
86
+
87
+ # Jupyter Notebook
88
+ .ipynb_checkpoints
89
+
90
+ # IPython
91
+ profile_default/
92
+ ipython_config.py
93
+
94
+ # pyenv
95
+ # For a library or package, you might want to ignore these files since the code is
96
+ # intended to run in multiple environments; otherwise, check them in:
97
+ # .python-version
98
+
99
+ # pipenv
100
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
101
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
102
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
103
+ # install all needed dependencies.
104
+ #Pipfile.lock
105
+
106
+ # poetry
107
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
108
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
109
+ # commonly ignored for libraries.
110
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
111
+ #poetry.lock
112
+
113
+ # pdm
114
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
115
+ #pdm.lock
116
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
117
+ # in version control.
118
+ # https://pdm.fming.dev/#use-with-ide
119
+ .pdm.toml
120
+
121
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
122
+ __pypackages__/
123
+
124
+ # Celery stuff
125
+ celerybeat-schedule
126
+ celerybeat.pid
127
+
128
+ # SageMath parsed files
129
+ *.sage.py
130
+
131
+ # Environments
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+
163
+ # PyCharm
164
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
167
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
+ #.idea/
169
+
170
+ uploads/
171
+
172
+ # End of https://www.toptal.com/developers/gitignore/api/flask
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ COPY . .
10
+
11
+ CMD ["gunicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, Response, send_file
2
+ from doctr.io import DocumentFile
3
+ from doctr.models import ocr_predictor
4
+ import os
5
+
6
+ UPLOAD_FOLDER = "uploads"
7
+ app = Flask(__name__)
8
+ app.config["UPLOAD_FOLDER"] = UPLOAD_FOLDER
9
+
10
+ if not os.path.isdir(app.config["UPLOAD_FOLDER"]):
11
+ os.mkdir(UPLOAD_FOLDER)
12
+
13
+ @app.route("/", methods=["GET"])
14
+ def hello():
15
+ return {"hello": "world"}
16
+
17
+ @app.route("/ocr", methods=["POST"])
18
+ def ocr():
19
+ if request.method == "POST":
20
+ if 'image' not in request.files:
21
+ print('hello')
22
+ return Response("Image Not Attached!", status=400)
23
+
24
+ img = request.files['image']
25
+ img_path = os.path.join(app.config["UPLOAD_FOLDER"], img.filename)
26
+ img.save(img_path)
27
+
28
+ model = ocr_predictor(pretrained=True)
29
+ doc = DocumentFile.from_images(img_path)
30
+
31
+ result = model(doc)
32
+
33
+ return result.render()
34
+
35
+
36
+
37
+ if __name__ == "__main__":
38
+ app.run(debug=True)
requirements.txt ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ blinker==1.7.0
2
+ Brotli==1.1.0
3
+ certifi==2024.2.2
4
+ cffi==1.16.0
5
+ charset-normalizer==3.3.2
6
+ click==8.1.7
7
+ colorama==0.4.6
8
+ contourpy==1.2.0
9
+ cryptography==42.0.5
10
+ cssselect2==0.7.0
11
+ cycler==0.12.1
12
+ defusedxml==0.7.1
13
+ filelock==3.13.1
14
+ Flask==3.0.2
15
+ fonttools==4.49.0
16
+ fsspec==2024.2.0
17
+ gunicorn==21.2.0
18
+ h5py==3.10.0
19
+ html5lib==1.1
20
+ huggingface-hub==0.21.3
21
+ idna==3.6
22
+ importlib-metadata==7.0.1
23
+ itsdangerous==2.1.2
24
+ Jinja2==3.1.3
25
+ kiwisolver==1.4.5
26
+ langdetect==1.0.9
27
+ MarkupSafe==2.1.5
28
+ matplotlib==3.8.3
29
+ mplcursors==0.5.3
30
+ numpy==1.26.4
31
+ opencv-python==4.9.0.80
32
+ packaging==23.2
33
+ pillow==10.2.0
34
+ pyclipper==1.3.0.post5
35
+ pycparser==2.21
36
+ pydyf==0.9.0
37
+ pyparsing==3.1.2
38
+ pypdfium2==4.27.0
39
+ pyphen==0.14.0
40
+ python-dateutil==2.9.0.post0
41
+ python-doctr==0.8.1
42
+ PyYAML==6.0.1
43
+ rapidfuzz==3.6.2
44
+ requests==2.31.0
45
+ scipy==1.12.0
46
+ shapely==2.0.3
47
+ six==1.16.0
48
+ tinycss2==1.2.1
49
+ tqdm==4.66.2
50
+ typing_extensions==4.10.0
51
+ Unidecode==1.3.8
52
+ urllib3==2.2.1
53
+ weasyprint==61.1
54
+ webencodings==0.5.1
55
+ Werkzeug==3.0.1
56
+ zipp==3.17.0
57
+ zopfli==0.2.3
58
+ tensorflow
59
+ tensorflow-addons
60
+ tf2onnx