rakib72642 commited on
Commit
0816a09
·
1 Parent(s): 5bde31b

fix issues

Browse files
ArabicOCR.log DELETED
File without changes
OLD/__pycache__/main.cpython-312.pyc DELETED
Binary file (2.06 kB)
 
__pycache__/ocr_main.cpython-312.pyc DELETED
Binary file (5.99 kB)
 
data/__pycache__/data.cpython-312.pyc DELETED
Binary file (309 Bytes)
 
data/__pycache__/model.cpython-312.pyc DELETED
Binary file (384 Bytes)
 
ocr_api.py CHANGED
@@ -72,13 +72,13 @@ async def create_items(items: Union[Item, List[Item]]):
72
  except Exception as e:
73
  global total_error
74
  total_error += 1
75
- logger.info(f"Time:{get_bd_time()}, Execution Failed and Total Failed Execution : {total_error}, Payload:{items}")
76
  logger.error(str(e))
77
  return {"AI": f"Error: {str(e)}"}
78
  finally:
79
  global total_done
80
  total_done +=1
81
- logger.info(f"Time:{get_bd_time()}, Execution Done and Total Successfull Execution : {total_done}, Payload:{items}")
82
  torch.cuda.empty_cache()
83
  pass
84
 
 
72
  except Exception as e:
73
  global total_error
74
  total_error += 1
75
+ logger.info(f"Time:{get_bd_time()}, Execution Failed and Total Failed Execution : {total_error}, Payload:{items}, Error:{str(e)}")
76
  logger.error(str(e))
77
  return {"AI": f"Error: {str(e)}"}
78
  finally:
79
  global total_done
80
  total_done +=1
81
+ logger.info(f"Time:{get_bd_time()}, Execution Done and Total Successfull Execution : {total_done}, Payload:{items}, Result:{results}")
82
  torch.cuda.empty_cache()
83
  pass
84
 
ocr_main.py CHANGED
@@ -8,7 +8,6 @@ from io import BytesIO
8
  from data.model import OCR_model
9
  from data.data import name_distribute
10
 
11
-
12
  async def getImage(img_url):
13
  async with ClientSession() as session:
14
  try:
@@ -19,8 +18,6 @@ async def getImage(img_url):
19
  print({"Error in getImage":str(e)})
20
 
21
 
22
-
23
-
24
  async def detection(model,img_content):
25
  try:
26
  img = Image.open(img_content)
@@ -30,10 +27,10 @@ async def detection(model,img_content):
30
  detection = {}
31
  data = json.loads(result[0].tojson())
32
  rect_data = []
33
- rec_rect = []
34
  for items in data:
35
  rect_data.append(items["box"])
36
- await create_rectangle(img_content,rect_data)
 
37
  if len(data) == 0:
38
  res = {"AI": "No Detection"}
39
  detection.update(res)
@@ -44,20 +41,24 @@ async def detection(model,img_content):
44
  for name, count in name_counts.items():
45
  res = {name: count}
46
  detection.update(res)
47
- return detection
48
  except Exception as e:
49
  print({"Error in detection":str(e)})
50
 
51
 
52
  async def share_iamge(img):
53
  try:
 
54
  buffer = BytesIO()
55
  img.save(buffer, format="JPEG")
56
  base64_image = base64.b64encode(buffer.getvalue()).decode("utf-8")
57
- return base64_image
 
58
  except Exception as e:
59
  print({"Error in share_iamge":str(e)})
60
 
 
 
61
  async def create_rectangle(image_data,cords):
62
  try:
63
  drawing = ImageDraw.Draw(image_data)
@@ -67,8 +68,8 @@ async def create_rectangle(image_data,cords):
67
  x2 = item["x2"]
68
  y1 = item["y1"]
69
  y2 = item["y2"]
70
- drawing.rectangle([x1,y1,x2,y2],outline="red",width=5)
71
- return drawing
72
  except Exception as e:
73
  print({"Error in create_rectangle":str(e)})
74
 
@@ -96,13 +97,12 @@ async def format_result(res,conv):
96
  async def mainDet(url):
97
  try:
98
  image = await asyncio.create_task(getImage(url))
99
- detect_data = await asyncio.create_task(detection(OCR_model, image))
100
  tab_data = await asyncio.create_task(format_result(detect_data,name_distribute))
101
- img_data = await asyncio.create_task(share_iamge(image))
102
-
103
  result = {
104
- "tabularData":tab_data,
105
- "imageData":img_data,
106
  }
107
  return json.dumps(result)
108
 
 
8
  from data.model import OCR_model
9
  from data.data import name_distribute
10
 
 
11
  async def getImage(img_url):
12
  async with ClientSession() as session:
13
  try:
 
18
  print({"Error in getImage":str(e)})
19
 
20
 
 
 
21
  async def detection(model,img_content):
22
  try:
23
  img = Image.open(img_content)
 
27
  detection = {}
28
  data = json.loads(result[0].tojson())
29
  rect_data = []
 
30
  for items in data:
31
  rect_data.append(items["box"])
32
+ print(items["box"])
33
+ img = await create_rectangle(Image.open(img_content),rect_data)
34
  if len(data) == 0:
35
  res = {"AI": "No Detection"}
36
  detection.update(res)
 
41
  for name, count in name_counts.items():
42
  res = {name: count}
43
  detection.update(res)
44
+ return detection, img
45
  except Exception as e:
46
  print({"Error in detection":str(e)})
47
 
48
 
49
  async def share_iamge(img):
50
  try:
51
+ # img = Image.open(imgs)
52
  buffer = BytesIO()
53
  img.save(buffer, format="JPEG")
54
  base64_image = base64.b64encode(buffer.getvalue()).decode("utf-8")
55
+ data = {"Arabic Detected": base64_image}
56
+ return data
57
  except Exception as e:
58
  print({"Error in share_iamge":str(e)})
59
 
60
+
61
+
62
  async def create_rectangle(image_data,cords):
63
  try:
64
  drawing = ImageDraw.Draw(image_data)
 
68
  x2 = item["x2"]
69
  y1 = item["y1"]
70
  y2 = item["y2"]
71
+ drawing.rectangle([x1,y1,x2,y2],outline="red",width=1)
72
+ return image_data
73
  except Exception as e:
74
  print({"Error in create_rectangle":str(e)})
75
 
 
97
  async def mainDet(url):
98
  try:
99
  image = await asyncio.create_task(getImage(url))
100
+ detect_data,img = await asyncio.create_task(detection(OCR_model, image))
101
  tab_data = await asyncio.create_task(format_result(detect_data,name_distribute))
102
+ img_data = await asyncio.create_task(share_iamge(img))
 
103
  result = {
104
+ "tabularData":{} if len(tab_data)==0 else tab_data,
105
+ "imageData":{} if img_data == None else img_data,
106
  }
107
  return json.dumps(result)
108