Ntchinda-Giscard commited on
Commit
807d8cf
1 Parent(s): 8185dd4
Files changed (2) hide show
  1. app.py +9 -11
  2. utils.py +1 -20
app.py CHANGED
@@ -4,7 +4,7 @@ from fastapi import FastAPI, File, UploadFile, HTTPException
4
  from fastapi.responses import HTMLResponse, JSONResponse
5
  import os
6
  from fastapi.middleware.cors import CORSMiddleware
7
- from utils import crop_images_from_detections, detect_licensePlate, licence_dect, lookup_user, lookup_user_metadata, ner_recog, read_text_img, upload_to_s3, vehicle_dect, write_to_upload
8
  # from pinecone import Pinecone
9
  # from deepface import DeepFace
10
 
@@ -203,14 +203,14 @@ async def upload_files(
203
  front_url = upload_to_s3(front_path)
204
  back_url = upload_to_s3(back_path)
205
 
206
- front_text = read_text_img(front_path)
207
- back_text = read_text_img(back_path)
208
 
209
- ent_front = ner_recog(front_text)
210
- ent_back = ner_recog(back_text)
211
 
212
- print(f"[*] ---- Entity front ----> {ent_front}")
213
- print(f"[*] ---- Entity back ----> {ent_back}")
214
 
215
  if face is not None:
216
  # Save the face image to disk
@@ -219,9 +219,7 @@ async def upload_files(
219
  face_file.write(await face.read())
220
  face_url = upload_to_s3(face_path)
221
  serial_number = ''
222
- for i in ent_back["entities"]:
223
- if 'serial' in i:
224
- serial_number = i['serial']
225
 
226
 
227
  print(f"[*] --- Serial ---> {serial_number}")
@@ -251,7 +249,7 @@ async def upload_files(
251
 
252
 
253
 
254
- return JSONResponse(content = {"message": "Upload successful", "data":{"text_front": f'{front_text}', 'front_url': front_url , 'entity_front': front_id, 'text_back': f'{back_text}', 'back_url': back_url, 'entity_back': back_id}}, status_code=200)
255
  except Exception as e:
256
  return HTTPException(status_code=500, detail=f"Internal server error {str(e)}")
257
 
 
4
  from fastapi.responses import HTMLResponse, JSONResponse
5
  import os
6
  from fastapi.middleware.cors import CORSMiddleware
7
+ from utils import crop_images_from_detections, detect_licensePlate, upload_to_s3
8
  # from pinecone import Pinecone
9
  # from deepface import DeepFace
10
 
 
203
  front_url = upload_to_s3(front_path)
204
  back_url = upload_to_s3(back_path)
205
 
206
+ # front_text = read_text_img(front_path)
207
+ # back_text = read_text_img(back_path)
208
 
209
+ # ent_front = ner_recog(front_text)
210
+ # ent_back = ner_recog(back_text)
211
 
212
+ # print(f"[*] ---- Entity front ----> {ent_front}")
213
+ # print(f"[*] ---- Entity back ----> {ent_back}")
214
 
215
  if face is not None:
216
  # Save the face image to disk
 
219
  face_file.write(await face.read())
220
  face_url = upload_to_s3(face_path)
221
  serial_number = ''
222
+
 
 
223
 
224
 
225
  print(f"[*] --- Serial ---> {serial_number}")
 
249
 
250
 
251
 
252
+ return JSONResponse(content = {"message": "Upload successful", "data":{'front_url': front_url , 'entity_front': front_id, 'back_url': back_url, 'entity_back': back_id}}, status_code=200)
253
  except Exception as e:
254
  return HTTPException(status_code=500, detail=f"Internal server error {str(e)}")
255
 
utils.py CHANGED
@@ -183,19 +183,10 @@ def detect_licensePlate(img: str) -> dict:
183
 
184
  return final
185
 
186
- # if len(results > 1):
187
- # for result in results:
188
- # boxes = result.boxes.xyxy
189
- # for box in boxes.numpy():
190
- # x1, y1, x2, y2 = box[0], box[1], box[2], box[3]
191
- # cropped_image = image.crop((x1, y1, x2, y2))
192
- # color =
193
 
194
 
195
 
196
 
197
- return results
198
-
199
 
200
  def licence_dect(img: str) -> list:
201
  image = Image.open(img)
@@ -298,11 +289,7 @@ def vehicle_dect(img: str) -> any:
298
  logger.info("[*]---- Color detecttion : f{color}")
299
 
300
  logger.info("[*]---- Classes detecttion : f{classes}")
301
-
302
- # {'color': (70, 69, 74), 'plate': ['LT661HM CMR ']}
303
- # ['car', 'car']
304
- # {'color': (73, 82, 89), 'plate': []}
305
- # ['car', 'car']
306
 
307
  for i in range(len(classes)):
308
  final.append({ "type": classes[i], "car_data" : colors[i]})
@@ -313,12 +300,6 @@ def vehicle_dect(img: str) -> any:
313
  # raise(e)
314
  pass
315
 
316
- def write_to_upload( file, file_path, folder= "uploads"):
317
- path = os.path.join(folder, file_path)
318
- with open(path, "wb") as front_file:
319
- front_file.write( file.read())
320
- return path
321
-
322
  # res = licence_dect("cars.jpg")
323
  # print(res)
324
 
 
183
 
184
  return final
185
 
 
 
 
 
 
 
 
186
 
187
 
188
 
189
 
 
 
190
 
191
  def licence_dect(img: str) -> list:
192
  image = Image.open(img)
 
289
  logger.info("[*]---- Color detecttion : f{color}")
290
 
291
  logger.info("[*]---- Classes detecttion : f{classes}")
292
+
 
 
 
 
293
 
294
  for i in range(len(classes)):
295
  final.append({ "type": classes[i], "car_data" : colors[i]})
 
300
  # raise(e)
301
  pass
302
 
 
 
 
 
 
 
303
  # res = licence_dect("cars.jpg")
304
  # print(res)
305