-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
119 lines (92 loc) · 3.67 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
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
from flask import Flask, render_template, request, redirect, url_for, flash, jsonify
import numpy as np
from PIL import Image
import base64
import os
import re
from io import StringIO, BytesIO
import face_recognition
import time
import requests
app = Flask(__name__)
@app.route("/", methods=['GET', 'POST'])
def hello_world():
filepath = "NOT FOUND"
filepath2 = "NOT FOUND"
global pan
if request.method == 'POST':
img = request.files['photograph']
card = request.files['pan-card']
name = request.form['f-name']
pan = request.form['pan-card-number']
if not os.path.isdir('static/user'):
os.mkdir('static/user')
#if 'static\user\user.jpg' is found, delete it
if os.path.isfile('static/user/user.jpg'):
os.remove('static/user/user.jpg')
#if 'static\user\user.jpg' is found, delete it
if os.path.isfile('static/user/pan_user.jpg'):
os.remove('static/user/pan_user.jpg')
filepath = os.path.join('static/user', img.filename)
filepath2 = os.path.join('static/user', card.filename)
newName = "static/user/user.jpg"
newName2 = "static/user/pan_user.jpg"
img.save(filepath)
card.save(filepath2)
fp = os.rename(filepath, newName)
fp2 = os.rename(filepath2, newName2)
return redirect(url_for('verify'))
return render_template('signupkyc.html')
@app.route("/verify", methods=['GET', 'POST'])
def verify():
if request.method=='POST':
time.sleep(5)
original=face_recognition.load_image_file('static/user/user.jpg')
captured=face_recognition.load_image_file('static/image.png')
knownFace=[]
knownEncoding=face_recognition.face_encodings(original)[0]
knownFace.append(knownEncoding)
unknownEncodings=face_recognition.face_encodings(captured)
if len(unknownEncodings)>0:
result=face_recognition.compare_faces(knownFace,unknownEncodings[0])
else:
return redirect(url_for('verify'))
if result==[True]:
return redirect(url_for('status'))
elif result==[False]:
return redirect(url_for('verify'))
return render_template('pic_capture.html')
@app.route('/hook', methods=['POST','GET'])
def hook():
image_b64 = request.values['imageBase64']
image_data = re.sub('^data:image/.+;base64,', '', image_b64)
image_data = base64.b64decode(str(image_data))
image_PIL = Image.open(BytesIO(image_data))
image_save = image_PIL.save('static/image.png')
return ''
@app.route("/status",methods=['POST','GET'])
def status():
global pan
if request.method=='POST':
time.sleep(5)
file='static/image.png'
url = 'https://app.nanonets.com/api/v2/OCR/Model/9e4e102b-3c93-4e4c-bf56-44a513db95dd/LabelFile/'
data = {'file': open(file, 'rb')}
response = requests.post(url, auth=requests.auth.HTTPBasicAuth('VMKD_k5J8_RNlzO9chHTYbnAjvuHbn63', ''), files=data)
line=response.text
ind=line.find('ocr_text')
num=line[ind+11:ind+21]
if(line == None):
return redirect(url_for('status'))
if(len(num) == 10 and num==pan):
return redirect(url_for('pan_status'))
return redirect(url_for("status"))
return render_template('pan_veri.html');
@app.route('/pan_status',methods=['POST','GET'])
def pan_status():
os.remove('static\\user\\pan_user.jpg')
os.remove('static\\user\\user.jpg')
os.remove('static\\image.png')
return render_template('user_confirm.html')
if __name__ == '__main__':
app.run(debug=True)