kavg commited on
Commit
75c54a9
1 Parent(s): 42b912c

fixed erros with handwritten ocr

Browse files
Files changed (2) hide show
  1. main.py +2 -2
  2. ocr.py +3 -3
main.py CHANGED
@@ -76,10 +76,10 @@ def ApplyOCR(content):
76
  try:
77
  printed_img, handwritten_imgs = DetectHandwritting(image)
78
  except:
79
- raise HTTPException(status_code=400, detail="Handwritten OCR failed")
80
 
81
  try:
82
- trocr_client = ocr.TrOCRClientClient(config['settings'].TROCR_API_URL)
83
  handwritten_ocr_df = trocr_client.ocr(handwritten_imgs, image)
84
  except:
85
  raise HTTPException(status_code=400, detail="handwritten OCR process failed")
 
76
  try:
77
  printed_img, handwritten_imgs = DetectHandwritting(image)
78
  except:
79
+ raise HTTPException(status_code=400, detail="Handwritting detection failed")
80
 
81
  try:
82
+ trocr_client = ocr.TrOCRClient(config['settings'].TROCR_API_URL)
83
  handwritten_ocr_df = trocr_client.ocr(handwritten_imgs, image)
84
  except:
85
  raise HTTPException(status_code=400, detail="handwritten OCR process failed")
ocr.py CHANGED
@@ -125,14 +125,14 @@ class TrOCRClient():
125
  # Check the response status code
126
  if response.status_code == 200:
127
  # Get the extracted text from the response
128
- extracted_text = response.json()["text"]
129
- print(extracted_text)
130
  else:
131
  print(f"Error: {response.text}")
 
132
 
133
  def ocr(self, handwritten_imgs, image):
134
  boxObjects = []
135
- for i in len(handwritten_imgs):
136
  handwritten_img = handwritten_imgs[i]
137
  ocr_result = self.send_request(handwritten_img[0])
138
  boxObjects.append({
 
125
  # Check the response status code
126
  if response.status_code == 200:
127
  # Get the extracted text from the response
128
+ extracted_text = response.json()["ocr_result"]
 
129
  else:
130
  print(f"Error: {response.text}")
131
+ return extracted_text
132
 
133
  def ocr(self, handwritten_imgs, image):
134
  boxObjects = []
135
+ for i in range(len(handwritten_imgs)):
136
  handwritten_img = handwritten_imgs[i]
137
  ocr_result = self.send_request(handwritten_img[0])
138
  boxObjects.append({