wajid commited on
Commit
bbef06d
·
1 Parent(s): f909d5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -6
app.py CHANGED
@@ -111,17 +111,48 @@ def extract_result(lst):
111
  name=lst[x][1][1]
112
  country=lst[x][1][2]
113
  nationality=lst[x][1][3]
 
114
  try:
115
  birth_date=datetime.strptime(lst[x][1][4], '%y%m%d').strftime('%d/%m/%Y')
116
  expiry_date=datetime.strptime(lst[x][1][5], '%y%m%d').strftime('%d/%m/%Y')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  except:
118
 
119
  birth_date=lst[x][1][4]#datetime.strptime(lst[x][1][4], '%y%m%d').strftime('%d/%m/%Y')
120
  expiry_date=lst[x][1][5]#datetime.strptime(lst[x][1][5], '%y%m%d').strftime('%d/%m/%Y')
121
-
 
 
 
 
122
  document_type=lst[x][1][7]
123
  document_number=lst[x][1][8]
124
- temp_lst.append([surname,name,country,birth_date,expiry_date,document_number])
125
 
126
  #temp_lst.append([surname,name,country,nationality,birth_date,expiry_date,document_type,document_number])
127
  final_lst.append(temp_lst)
@@ -133,17 +164,52 @@ def extract_result(lst):
133
  country=lst[x][2]
134
  nationality=lst[x][3]
135
  try:
 
136
  birth_date=datetime.strptime(lst[x][4], '%y%m%d').strftime('%d/%m/%Y')
137
  expiry_date=datetime.strptime(lst[x][5], '%y%m%d').strftime('%d/%m/%Y')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  except:
139
  birth_date=lst[x][4]#datetime.strptime(lst[x][4], '%y%m%d').strftime('%d/%m/%Y')
140
  expiry_date=lst[x][5]#datetime.strptime(lst[x][5], '%y%m%d').strftime('%d/%m/%Y')
 
 
141
 
142
  document_type=lst[x][7]
143
  document_number=lst[x][8]
144
 
145
  if document_type=="P" or document_type=="p":# or document_type=="PM" or document_type=="PO":
146
- temp_lst.append([surname,name,country,birth_date,expiry_date,document_number])
147
  else:
148
  print(lst)
149
  temp_lst.append("The attached document is not a Passport")
@@ -162,7 +228,7 @@ def return_df(final_lst):
162
  if final_lst[0]=="The attached document is not a Passport":
163
  return "The attached document is not a Passport"
164
  else:
165
- columns = ['family_name','given_name','country','date_of_birth','expiration','passport_number']
166
  #columns = ['family_name','given_name','country','nationality','date_of_birth','expiration','document_type','passport_number']
167
 
168
  res = {columns[i]: final_lst[0][i] for i in range(len(columns))}
@@ -287,5 +353,3 @@ uvicorn.run(app, host="0.0.0.0", port=7860)
287
  #app.mount(CUSTOM_PATH, gradio_app)
288
  #io.launch()
289
 
290
-
291
-
 
111
  name=lst[x][1][1]
112
  country=lst[x][1][2]
113
  nationality=lst[x][1][3]
114
+
115
  try:
116
  birth_date=datetime.strptime(lst[x][1][4], '%y%m%d').strftime('%d/%m/%Y')
117
  expiry_date=datetime.strptime(lst[x][1][5], '%y%m%d').strftime('%d/%m/%Y')
118
+ year=datetime.strptime(lst[x][1][5], '%y%m%d').year
119
+ month=datetime.strptime(lst[x][1][5], '%y%m%d').month
120
+ day=datetime.strptime(lst[x][1][5], '%y%m%d').day
121
+ if nationality=='TWN':
122
+ year-=5
123
+ else:
124
+ year-=10
125
+
126
+ if nationality=='IND' or nationality=='CHN' or nationality=='BRA':
127
+
128
+ if str(day)=="31":
129
+ day=1
130
+ month+=1
131
+ else:
132
+ day+=1
133
+
134
+ str_day=day
135
+ str_month=month
136
+ if len(str(day))==1:
137
+ str_day="0"+str(day)
138
+
139
+ if len(str(month))==1:
140
+ str_month="0"+str(month)
141
+
142
+
143
+ issue_date=str(str_day)+"/"+str(str_month)+"/"+str(year)
144
  except:
145
 
146
  birth_date=lst[x][1][4]#datetime.strptime(lst[x][1][4], '%y%m%d').strftime('%d/%m/%Y')
147
  expiry_date=lst[x][1][5]#datetime.strptime(lst[x][1][5], '%y%m%d').strftime('%d/%m/%Y')
148
+
149
+
150
+
151
+ issue_date=expiry_date
152
+
153
  document_type=lst[x][1][7]
154
  document_number=lst[x][1][8]
155
+ temp_lst.append([surname,name,country,birth_date,expiry_date,document_number,issue_date])
156
 
157
  #temp_lst.append([surname,name,country,nationality,birth_date,expiry_date,document_type,document_number])
158
  final_lst.append(temp_lst)
 
164
  country=lst[x][2]
165
  nationality=lst[x][3]
166
  try:
167
+
168
  birth_date=datetime.strptime(lst[x][4], '%y%m%d').strftime('%d/%m/%Y')
169
  expiry_date=datetime.strptime(lst[x][5], '%y%m%d').strftime('%d/%m/%Y')
170
+ year=datetime.strptime(lst[x][5], '%y%m%d').year
171
+ month=datetime.strptime(lst[x][5], '%y%m%d').month
172
+ day=datetime.strptime(lst[x][5], '%y%m%d').day
173
+
174
+ if nationality=='TWN':
175
+ year-=5
176
+ else:
177
+ year-=10
178
+
179
+
180
+ if country=='IND' or nationality=='CHN' or nationality=='BRA':
181
+
182
+ if str(day)=="31":
183
+ day=1
184
+ month+=1
185
+ else:
186
+ day+=1
187
+ str_day=day
188
+ str_month=month
189
+
190
+
191
+ if len(str(day))==1:
192
+ str_day="0"+str(day)
193
+
194
+ if len(str(month))==1:
195
+ str_month="0"+str(month)
196
+
197
+
198
+ issue_date=str(str_day)+"/"+str(str_month)+"/"+str(year)
199
+
200
+
201
+
202
  except:
203
  birth_date=lst[x][4]#datetime.strptime(lst[x][4], '%y%m%d').strftime('%d/%m/%Y')
204
  expiry_date=lst[x][5]#datetime.strptime(lst[x][5], '%y%m%d').strftime('%d/%m/%Y')
205
+ issue_date=expiry_date
206
+
207
 
208
  document_type=lst[x][7]
209
  document_number=lst[x][8]
210
 
211
  if document_type=="P" or document_type=="p":# or document_type=="PM" or document_type=="PO":
212
+ temp_lst.append([surname,name,country,birth_date,expiry_date,document_number,issue_date])
213
  else:
214
  print(lst)
215
  temp_lst.append("The attached document is not a Passport")
 
228
  if final_lst[0]=="The attached document is not a Passport":
229
  return "The attached document is not a Passport"
230
  else:
231
+ columns = ['family_name','given_name','country','date_of_birth','expiration','passport_number','issue_date']
232
  #columns = ['family_name','given_name','country','nationality','date_of_birth','expiration','document_type','passport_number']
233
 
234
  res = {columns[i]: final_lst[0][i] for i in range(len(columns))}
 
353
  #app.mount(CUSTOM_PATH, gradio_app)
354
  #io.launch()
355