Spaces:
Running
Running
resolved the filename issue in which filename cannot have dot
Browse files
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 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
files[key] = response["output_p"] + "&&" + f_path
|
293 |
-
# files["unprocessed_file_path"] = f_path
|
294 |
-
print("response",response)
|
295 |
|
296 |
-
|
297 |
-
|
298 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
299 |
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
# if result["status"] == "error":
|
304 |
-
|
305 |
|
|
|
|
|
|
|
|
|
|
|
306 |
|
307 |
-
return {"status": "success", "result": result}
|
308 |
|
|
|
309 |
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
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 |
-
|
12 |
-
|
13 |
|
14 |
# sys.exit()
|
15 |
|
16 |
post_url = "http://localhost:7680/api/aadhar_ocr"
|
17 |
|
|
|
|
|
|
|
18 |
# response = requests.get(url)
|
19 |
|
20 |
-
|
21 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
files = {
|
23 |
-
"aadhar_file": open("/Users/javed/Downloads/test_images_folder/aadhar/22.jpg", "rb")
|
24 |
-
# "pan_file": open("/Users/javed/
|
25 |
-
# "cheque_file": open("/Users/javed/
|
26 |
-
|
|
|
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 |
|