AuditEdge commited on
Commit
e709d2a
·
1 Parent(s): 3bb9361

resolved the filename issue in which filename cannot have dot

Browse files
Files changed (3) hide show
  1. app.py +51 -42
  2. sample.py +18 -8
  3. utils.py +2 -0
app.py CHANGED
@@ -224,6 +224,8 @@ def perform_inference(file_paths: Dict[str, str]):
224
  # upload the document to s3 bucket here
225
 
226
 
 
 
227
  response = client.upload_file(local_file_path,bucket_name,folder_name,file_name)
228
 
229
  print("The file has been uploaded to s3 bucket",response)
@@ -265,54 +267,61 @@ async def aadhar_ocr(
265
  cheque_file: UploadFile = File(None),
266
  gst_file: UploadFile = File(None),
267
  ):
268
- try:
269
  # Handle file uploads
270
- file_paths = {}
271
- for file_type, folder in UPLOAD_DIRS.items():
272
- file = locals()[file_type] # Dynamically access the file arguments
273
- if file:
274
- # Save the file in the respective directory
275
- file_path = os.path.join(folder, file.filename)
276
- with open(file_path, "wb") as buffer:
277
- shutil.copyfileobj(file.file, buffer)
278
- file_paths[file_type] = file_path
279
-
280
- # Log received files
281
- logging.info(f"Received files: {list(file_paths.keys())}")
282
- print("file_paths",file_paths)
283
-
284
- files = {}
285
- for key, value in file_paths.items():
286
- name = value.split("/")[-1].split(".")[0]
287
- id_type = key.split("_")[0]
288
- doc_type = value.split("/")[-1].split(".")[1]
289
- f_path = value
290
- preprocessing = doc_processing(name,id_type,doc_type,f_path)
291
- response = preprocessing.process()
292
- files[key] = response["output_p"] + "&&" + f_path
293
- # files["unprocessed_file_path"] = f_path
294
- print("response",response)
295
 
296
-
297
- # Perform inference
298
- result = perform_inference(files)
 
 
 
 
 
 
299
 
300
- print("this is the result we got",result)
301
- if "status" in list(result.keys()):
302
- raise Exception("Custom error message")
303
- # if result["status"] == "error":
304
-
305
 
 
 
 
 
 
306
 
307
- return {"status": "success", "result": result}
308
 
 
309
 
310
- except Exception as e:
311
- logging.error(f"Error processing files: {e}")
312
- # raise HTTPException(status_code=500, detail="Internal Server Error")
313
- return {
314
- "status": 400,
315
- "message": "Text extraction failed."
316
- }
 
317
 
318
 
 
224
  # upload the document to s3 bucket here
225
 
226
 
227
+ print("this is folder name",folder_name)
228
+
229
  response = client.upload_file(local_file_path,bucket_name,folder_name,file_name)
230
 
231
  print("The file has been uploaded to s3 bucket",response)
 
267
  cheque_file: UploadFile = File(None),
268
  gst_file: UploadFile = File(None),
269
  ):
270
+ # try:
271
  # Handle file uploads
272
+ file_paths = {}
273
+ for file_type, folder in UPLOAD_DIRS.items():
274
+ file = locals()[file_type] # Dynamically access the file arguments
275
+ if file:
276
+ # Save the file in the respective directory
277
+ file_path = os.path.join(folder, file.filename)
278
+
279
+ print("this is the filename",file.filename)
280
+ with open(file_path, "wb") as buffer:
281
+ shutil.copyfileobj(file.file, buffer)
282
+ file_paths[file_type] = file_path
283
+
284
+ # Log received files
285
+ logging.info(f"Received files: {list(file_paths.keys())}")
286
+ print("file_paths",file_paths)
287
+
288
+ files = {}
289
+ for key, value in file_paths.items():
290
+ name = value.split("/")[-1].split(".")[0]
291
+ id_type = key.split("_")[0]
292
+ doc_type = value.split("/")[-1].split(".")[-1]
293
+ f_path = value
 
 
 
294
 
295
+ print("variables required",name,id_type,doc_type,f_path)
296
+ preprocessing = doc_processing(name,id_type,doc_type,f_path)
297
+ response = preprocessing.process()
298
+
299
+ print("response after preprocessing",response)
300
+
301
+ files[key] = response["output_p"] + "&&" + f_path
302
+ # files["unprocessed_file_path"] = f_path
303
+ print("response",response)
304
 
305
+
306
+ # Perform inference
307
+ result = perform_inference(files)
 
 
308
 
309
+ print("this is the result we got",result)
310
+ if "status" in list(result.keys()):
311
+ raise Exception("Custom error message")
312
+ # if result["status"] == "error":
313
+
314
 
 
315
 
316
+ return {"status": "success", "result": result}
317
 
318
+
319
+ # except Exception as e:
320
+ # logging.error(f"Error processing files: {e}")
321
+ # # raise HTTPException(status_code=500, detail="Internal Server Error")
322
+ # return {
323
+ # "status": 400,
324
+ # "message": "Text extraction failed."
325
+ # }
326
 
327
 
sample.py CHANGED
@@ -8,22 +8,32 @@ import sys
8
  # response = requests.get(url)
9
 
10
 
11
- # print("Status Code:", response.status_code)
12
- # print("Response Text:", response.text)
13
 
14
  # sys.exit()
15
 
16
  post_url = "http://localhost:7680/api/aadhar_ocr"
17
 
 
 
 
18
  # response = requests.get(url)
19
 
20
- # print()
21
- # Define the file pathscd
 
 
 
 
 
 
22
  files = {
23
- "aadhar_file": open("/Users/javed/Downloads/test_images_folder/aadhar/22.jpg", "rb")
24
- # "pan_file": open("/Users/javed/model_one/test_images_pan/6ea33087.jpeg", "rb"),
25
- # "cheque_file": open("/Users/javed/model_one/test_images_cheque/0f81678a.jpeg", "rb"),
26
- # "gst_file": open("/Users/javed/model_one/test_images_gst/0a52fbcb_page3_image_0.jpg", "rb"),
 
27
  }
28
 
29
  response = requests.post(post_url, files=files)
 
8
  # response = requests.get(url)
9
 
10
 
11
+
12
+
13
 
14
  # sys.exit()
15
 
16
  post_url = "http://localhost:7680/api/aadhar_ocr"
17
 
18
+ # post_url = "https://auditedge-optimised-ocr.hf.space/api/aadhar_ocr"
19
+ # url = "https://auditedge-optimised-ocr.hf.space/"
20
+
21
  # response = requests.get(url)
22
 
23
+
24
+ # print("Status Code:", response.status_code)
25
+ # print("Response Text:", response.text)
26
+
27
+
28
+
29
+ # # print()
30
+ # # Define the file pathscd
31
  files = {
32
+ # "aadhar_file": open("/Users/javed/Downloads/test_images_folder/aadhar/22.jpg", "rb")
33
+ # "pan_file": open("/Users/javed/Downloads/test_images_folder/pan/fcc.14eb7.jpg", "rb"),
34
+ # "cheque_file": open("/Users/javed/Downloads/test_images_folder/cheque/2.jpeg", "rb"),
35
+ "gst_file": open("/Users/javed/Downloads/test_images_folder/gst/e.2.pdf", "rb")
36
+ # "gst_file": open("/Users/javed/Downloads/test_images_folder/gst/x.pdf", "rb")
37
  }
38
 
39
  response = requests.post(post_url, files=files)
utils.py CHANGED
@@ -46,6 +46,8 @@ class doc_processing:
46
 
47
  def scale_img(self):
48
 
 
 
49
  image = Image.open(self.f_path).convert("RGB")
50
  original_width, original_height = image.size
51
 
 
46
 
47
  def scale_img(self):
48
 
49
+
50
+ print("path of file",self.f_path)
51
  image = Image.open(self.f_path).convert("RGB")
52
  original_width, original_height = image.size
53