-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
55 lines (44 loc) · 1.73 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from flask import Flask, request, Response, redirect
import base64
import jsonpickle
from datetime import datetime
from dateExt import dateExtractor
from textExt import TesseractTxtExtractor
from preProc import preProcessor
import pandas as pd
import os
from PIL import Image
import cv2 as cv
app = Flask(__name__)
pp = preProcessor()
tx = TesseractTxtExtractor()
dx = dateExtractor()
@app.route("/extract_date", methods=['GET','POST'])
def index():
if request.method == "POST":
try:
r = request
image_64_decode = base64.decodestring(r.data)
image_result = open('recieved_img.jpeg', 'wb')
image_result.write(image_64_decode)
mtx = cv.imread('recieved_img.jpeg')
# Writ logic here to perform manipulation on image
mtx = pp.rescale(mtx)
content = tx.extractTxt(mtx)
date = dx.extractDate(content)
# Return response:
response = {'date' : date }
# encode response using jsonpickle
response_pickled = jsonpickle.encode(response)
except Exception as e:
response = {'date': 'null'}
response_pickled = jsonpickle.encode(response)
return Response(response=response_pickled, status=200, mimetype="application/json")
# print(r.data)
elif request.method=="GET":
response_pickled = "Make a POST request and see the result on your console"
return Response(response=response_pickled, status=200, mimetype="application/json")
# else:
# return Response(response="No Data", status=200, mimetype="application/json")
if __name__ == "__main__":
app.run(debug = True, host="0.0.0.0")