Mitul Mohammad Abdullah Al Mukit commited on
Commit
d357ee3
1 Parent(s): 1f72938

second commit

Browse files
Files changed (1) hide show
  1. app.py +209 -0
app.py ADDED
@@ -0,0 +1,209 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import similarity_check as sc
3
+ import cv2
4
+ from PIL import Image
5
+ import numpy as np
6
+ import tempfile
7
+ from streamlit_webrtc import VideoTransformerBase, webrtc_streamer
8
+ import demo
9
+ import time
10
+ import streamlit as st
11
+ import requests
12
+ import json
13
+ import request_json.sbt_request_generator as sbt
14
+
15
+ global data
16
+ data = {}
17
+
18
+
19
+ def main():
20
+ # st.title("SBT Web Application")
21
+ # today's date = get_today_date
22
+
23
+ # global data
24
+ html_temp = """
25
+ <body style="background-color:red;">
26
+ <div style="background-color:teal ;padding:10px">
27
+ <h2 style="color:white;text-align:center;">SBT Web Application</h2>
28
+ </div>
29
+ </body>
30
+ """
31
+ st.markdown(html_temp, unsafe_allow_html=True)
32
+
33
+ st.header("I. Similarity Check")
34
+ image_file = st.file_uploader("Upload Image", type=['jpg', 'png', 'jpeg'], accept_multiple_files=True)
35
+ if len(image_file) == 1:
36
+ # print(image_file[0].name)
37
+ image1 = Image.open(image_file[0])
38
+ st.text("HKID card")
39
+ st.image(image1)
40
+ elif len(image_file) == 2:
41
+ image1 = Image.open(image_file[0])
42
+ st.text("HKID card")
43
+ st.image(image1)
44
+ image2 = Image.open(image_file[1])
45
+ file_name = image_file[1].name
46
+ st.text("Bank statement")
47
+ st.image(image2)
48
+
49
+ # if image_file2 is not None:
50
+ # image2 = Image.open(image_file)
51
+ # st.text("Bank statement")
52
+ # st.image(image2)
53
+
54
+ # path1 = 'IMG_4495.jpg'
55
+ # path2 = 'hangseng_page-0001.jpg'
56
+ # image1 = save_image(image1)
57
+ # image2 = save_image(image2)
58
+
59
+ data = {}
60
+ if st.button("Recognise"):
61
+ with st.spinner('Wait for it...'):
62
+ # global data
63
+ data = sc.get_data(image1, image2, file_name)
64
+
65
+ with open('data1.txt', 'w') as f:
66
+ f.write(json.dumps(data))
67
+ # data.update(sc.get_data(image1, image2, file_name))
68
+ print(f'data inside {data}')
69
+ # sbt.split_data(data)
70
+ st.success('Done!')
71
+ score = data["similarity_score"]
72
+ #print(score)
73
+ st.text(f'score: {score}')
74
+ if (score>85):
75
+ st.text(f'matched')
76
+ else:
77
+ st.text(f'unmatched')
78
+
79
+ st.header("IIa. HKID Data Extraction")
80
+ st.text(f'Name: {data["name_on_id"]}') # name is without space
81
+ st.text(f'HKID: {data["hkid"]} and validity: {data["validity"]}')
82
+ st.text(f'Date of issue: {data["issue_date"]}')
83
+
84
+ st.header("IIb. Bank Statement Data Extraction")
85
+ # st.write('------------From bank statement------------')
86
+ st.text(f'Name: {data["name_on_bs"]}')
87
+ st.text(f'Address: {data["address"]}')
88
+ st.text(f'Bank: {data["bank"]}')
89
+ st.text(f'Date: {data["date"]}')
90
+ st.text(f'Asset: {data["asset"]} hkd')
91
+ st.text(f'Liabilities: {data["liabilities"]} hkd')
92
+ # result_img= detect_faces(our_image)
93
+ # st.image(result_img)
94
+ # print(f'data outside 1 {data}')
95
+
96
+ st.header("II. Facial Recognition")
97
+ run = st.checkbox('Run')
98
+
99
+ # webrtc_streamer(key="example")
100
+ # 1. Web Rtc
101
+ # webrtc_streamer(key="jhv", video_frame_callback=video_frame_callback)
102
+
103
+
104
+ # # init the camera
105
+ face_locations = []
106
+ # face_encodings = []
107
+ face_names = []
108
+ process_this_frame = True
109
+
110
+ score = []
111
+
112
+ faces = 0
113
+
114
+ FRAME_WINDOW = st.image([])
115
+ camera = cv2.VideoCapture(0)
116
+
117
+ while run:
118
+
119
+ # Capture frame-by-frame
120
+ # Grab a single frame of video
121
+ ret, frame = camera.read()
122
+
123
+ result, process_this_frame, face_locations, faces, face_names, score = demo.process_frame(frame, process_this_frame, face_locations, faces, face_names, score)
124
+ # Display the resulting image
125
+ FRAME_WINDOW.image(result)
126
+
127
+ print(score)
128
+ if len(score) > 20:
129
+ avg_score = sum(score) / len(score)
130
+ st.write(f'{avg_score}')
131
+ with open('data1.txt', 'w') as f:
132
+ data_raw = f.read()
133
+ data = json.loads(data_raw)
134
+ data['avg_score'] = str(avg_score)
135
+ f.write(json.dumps(data))
136
+
137
+
138
+ # update_text(f'{demo.convert_distance_to_percentage(score, 0.45)}')
139
+ else:
140
+ st.write('Stopped')
141
+
142
+
143
+ # print(f'the data is {data}')
144
+
145
+ # st.header("IIIa. HKID Data Extraction")
146
+ # st.text(f'Name: {data["name_on_id"]}') # name is without space
147
+ # st.text(f'HKID: {data["hkid"]} and validity: {data["validity"]}')
148
+ # st.text(f'Date of issue: {data["issue_date"]}')
149
+
150
+ # st.header("IIIb. Bank Statement Data Extraction")
151
+ # # st.write('------------From bank statement------------')
152
+ # st.text(f'Name: {data["name_on_bs"]}')
153
+ # st.text(f'Address: {data["address"]}')
154
+ # st.text(f'Bank: {data["bank"]}')
155
+ # st.text(f'Date: {data["date"]}')
156
+ # st.text(f'Asset: {data["asset"]} hkd')
157
+ # st.text(f'Liabilities: {data["liabilities"]} hkd')
158
+
159
+ # print(f'data outside 2 {data}')
160
+ if st.button("Confirm"):
161
+ # print(f'data outside 3 {data}')
162
+ with st.spinner('Sending data...'):
163
+ sbt.split_data(data)
164
+ st.success('Done!')
165
+
166
+ if __name__ == '__main__':
167
+ main()
168
+
169
+
170
+
171
+ # def save_image(image):
172
+ # try:
173
+ # temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.jpg')
174
+ # Image.save(temp_file.name)
175
+ # return temp_file.name
176
+ # except IOError:
177
+ # print("Unable to save image to temporary file")
178
+ # return None
179
+
180
+ # json_file = 'request json\request_legalDocument.json'
181
+ # file = open(json_file, 'r')
182
+ # data = json.load(file)
183
+ # file.close()
184
+ # # Update data
185
+ # data.update(new_data)
186
+ # file = open(json_file, 'w')
187
+ # for item in data['request']['body']['formdata']:
188
+ # if item["key"] == "requestId":
189
+ # item["value"] = ""
190
+ # elif item["key"] == "userId":
191
+ # item["value"] = generate_token_id(2048)
192
+ # elif item["key"] == "endpoint":
193
+ # item["value"] = ""
194
+ # elif item["key"] == "apiType":
195
+ # item["value"] = ""
196
+ # elif item["key"] == "docType":
197
+ # item["value"] = "HKID"
198
+ # elif item["key"] == "nameDoc":
199
+ # item["value"] = new_data["name_on_id"]
200
+ # elif item["key"] == "docID":
201
+ # item["value"] = new_data["name_on_id"]
202
+ # elif item["key"] == "docValidity":
203
+ # item["value"] = new_data["validity"]
204
+ # elif item["key"] == "dateOfIssue":
205
+ # item["value"] = new_data["date_issue"]
206
+ # elif item["key"] == "matchingScore":
207
+ # item["value"] = new_data["similarity_score"]
208
+ # json.dump(data, file)
209
+ # file.close()