-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
148 lines (130 loc) · 6.75 KB
/
app.py
File metadata and controls
148 lines (130 loc) · 6.75 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
'''
|========================================================================================================|
|````````````````````````````````````````````````````````````````````````````````````````````````````````|
|`````````````````````````````````██████╗ █████╗ ████████╗ █████╗ ``````````````````````````````````````|
|`````````````````````````````````██╔══██╗██╔══██╗╚══██╔══╝██╔══██╗``````````````````````````````````````|
|`````````````````````````````````██║``██║███████║```██║```███████║``````````````````````````````````````|
|`````````````````````````````````██║``██║██╔══██║```██║```██╔══██║``````````````````````````````````````|
|`````````````````````````````````██████╔╝██║``██║```██║```██║``██║``````````````````````````````````````|
|`````````````````````````````````╚═════╝ ╚═╝``╚═╝```╚═╝```╚═╝``╚═╝``````````````````````````````````````|
|``````````````````````██████╗ ███████╗███╗```██╗██████╗ ███████╗██████╗ ███████╗````````````````````````|
|``````````````````````██╔══██╗██╔════╝████╗``██║██╔══██╗██╔════╝██╔══██╗██╔════╝````````````````````````|
|``````````````````````██████╔╝█████╗``██╔██╗`██║██║``██║█████╗``██████╔╝███████╗````````````````````````|
|``````````````````````██╔══██╗██╔══╝``██║╚██╗██║██║``██║██╔══╝``██╔══██╗╚════██║````````````````````````|
|``````````````````````██████╔╝███████╗██║ ╚████║██████╔╝███████╗██║``██║███████║````````````````````````|
|``````````````````````╚═════╝ ╚══════╝╚═╝ ╚═══╝╚═════╝ ╚══════╝╚═╝``╚═╝╚══════╝````````````````````````|
|========================================================================================================|
| Project for Axis Bank ( SIGNATURE RECOGNITION SYSTEM ) |
|========================================================================================================|
'''
from flask import Flask,render_template,request, redirect, url_for
from flask_socketio import SocketIO, emit
from werkzeug.utils import secure_filename
import time,csv,os
import pandas as pd
from prediction.preprocess.normalize import preprocess_signature
from prediction.predictor import *
import prediction.signet as signet
from prediction.cnn_model import TF_CNNModel
from prediction.lasagne_to_tf import copy_initializer, transpose_copy_initializer
app = Flask(__name__)
UPLOAD_FOLDER = '/'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.config['DEBUG'] = True
socketio = SocketIO(app,binary = True)
model = mod_load(TF_CNNModel,signet)
sess = ses_init()
## creating the PNG file of blob data--------------------------
def createPng(data,name="tmpImage.png"):
fh = open(name, "wb")
fh.write(data)
fh.close()
## storing in Database(CSV) -----------------------------------
def writeCSV(data):
base = [[data['accountNo'],data['customerName'],os.path.join("account_images",str(data['accountNo'])+".png") ]]
Database = open('Database.csv','a')
with Database:
writer = csv.writer(Database)
writer.writerows(base)
return True
def matchSign(data):
## create PNG Image of receiving BLOB Data-------------------
createPng(data['finalImage'])
real=pd.read_csv("Database.csv")
r = list(real[real.account_no == int(data["accountNo"])].signature_image)
if(len(r) == 0):
scanResult = {
'action': 'scan',
'accountNo' : data['accountNo'],
'customerName' : data['customerName'],
'verdict' : "LOST"
}
return scanResult
else:
#Prediction
dist = euc_distance(sess,list(real[real.account_no == int(data["accountNo"])].signature_image)[0],"tmpImage.png",model,preprocess_signature)
## Scan result will generate after compare the image -------------
scanResult = {
'action': 'scan',
'accountNo' : data['accountNo'],
'customerName' : data['customerName'],
'verdict' : "PASS" if dist < 9 else "FAIL",
'confidence' : str(dist),
}
return scanResult
def addData(data):
## response JSON package for showing results in frontend -----
response = {
'action': 'add',
'accountNo' : data['accountNo'],
'verdict' : 'added',
'customerName' : data['customerName']
}
if(writeCSV(data)):
createPng(data["finalImage"],name=os.path.join("account_images",str(data['accountNo'])+".png"))
response['performed'] = True
else:
response['performed'] = False
return response
@app.route('/index')
def index():
return render_template('index.html' )
@app.route('/databenders/asrs/api/start',methods=['POST'])
def uploadImage():
if request.method =='POST':
file = request.files['file[]']
if file:
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'],filename))
scanResult = {
'action': 'scan',
'accountNo' : '123456789',
'customerName' : 'test',
'verdict' : 'PASS',
'confidence' : 0.755,
}
return scanResult
@socketio.on('connect')
def connect():
print(' CONNECTED ! ')
socketio.emit('test','server is ready...')
@socketio.on('scan-blob')
def scanBlob(blob):
if(blob != '' ):
print('Server is receving Blob...')
Result = matchSign(blob)
time.sleep(2)
socketio.emit('result',Result)
else:
print('Blob is empty')
@socketio.on('add-blob')
def addBlob(blob):
if(blob != '' ):
print('Server is receving addBlob...')
time.sleep(2)
Result = addData(blob)
socketio.emit('result',Result)
else:
print('addBlob is empty')
if __name__ == '__main__':
socketio.run(app)