TVQuyet05 commited on
Commit
df713d3
·
1 Parent(s): 6f73189
Files changed (1) hide show
  1. pipeline_main.py +46 -6
pipeline_main.py CHANGED
@@ -148,9 +148,32 @@ class TechnicalDrawingPipeline:
148
  if conf_list:
149
  ocr_confidence = round(sum(conf_list) / len(conf_list), 3)
150
  except Exception as e:
151
- print(f" -> [CẢNH BÁO] Lỗi khi OCR Note đối tượng {i+1}: {e}. Đã bỏ qua để tránh crash.")
152
- ocr_content = "[OCR Error]"
153
- ocr_confidence = None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
 
155
  elif class_name == "Table":
156
  # => Nhận dạng Bảng & Xuất HTML
@@ -164,9 +187,26 @@ class TechnicalDrawingPipeline:
164
  ocr_content = "\n".join(html_strings)
165
  ocr_confidence = None # Tạm để Null cho Table
166
  except Exception as e:
167
- print(f" -> [CẢNH BÁO] Lỗi khi xử lý cấu trúc Table đối tượng {i+1}: {e}. Đã bỏ qua để tránh crash.")
168
- ocr_content = "[Table Extractor Error]"
169
- ocr_confidence = None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
 
171
  elif class_name == "PartDrawing":
172
  # Không ocr part drawing
 
148
  if conf_list:
149
  ocr_confidence = round(sum(conf_list) / len(conf_list), 3)
150
  except Exception as e:
151
+ print(f" -> [CẢNH BÁO] Lỗi khi OCR Note đối tượng {i+1} ({e}). Đang khởi tạo lại Backend...")
152
+ try:
153
+ del self.text_ocr
154
+ import gc
155
+ gc.collect()
156
+ self.text_ocr = PaddleOCR(use_angle_cls=True, lang='en', use_gpu=False, ocr_version='PP-OCRv4', show_log=False, use_mkldnn=False, enable_mkldnn=False, cpu_threads=1, ir_optim=False, use_tensorrt=False)
157
+
158
+ ocr_crop = np.copy(crop_img)
159
+ ocr_result = self.text_ocr.ocr(ocr_crop, cls=True)
160
+ lines = []
161
+ conf_list = []
162
+ if ocr_result and len(ocr_result) > 0 and ocr_result[0] is not None:
163
+ for box_info in ocr_result[0]:
164
+ text_val = box_info[1][0]
165
+ conf_val = float(box_info[1][1])
166
+ if conf_val > 0.6:
167
+ lines.append(text_val)
168
+ conf_list.append(conf_val)
169
+ ocr_content = "\n".join(lines)
170
+ if conf_list:
171
+ ocr_confidence = round(sum(conf_list) / len(conf_list), 3)
172
+ print(f" -> Đã tự phục hồi và OCR Note thành công đối tượng {i+1}!")
173
+ except Exception as reset_e:
174
+ print(f" -> [THẤT BẠI] Đã thử lại nhưng vẫn lỗi Note đối tượng {i+1}: {reset_e}")
175
+ ocr_content = "[OCR Error]"
176
+ ocr_confidence = None
177
 
178
  elif class_name == "Table":
179
  # => Nhận dạng Bảng & Xuất HTML
 
187
  ocr_content = "\n".join(html_strings)
188
  ocr_confidence = None # Tạm để Null cho Table
189
  except Exception as e:
190
+ print(f" -> [CẢNH BÁO] Lỗi cấu trúc Table đối tượng {i+1} ({e}). Đang khởi tạo lại Backend...")
191
+ try:
192
+ del self.table_ocr
193
+ import gc
194
+ gc.collect()
195
+ self.table_ocr = PPStructure(layout=False, table=True, ocr=True, show_log=False, recovery=True, lang='en', use_gpu=False, use_mkldnn=False, enable_mkldnn=False, cpu_threads=1, ir_optim=False, use_tensorrt=False)
196
+
197
+ tab_crop = np.copy(crop_img)
198
+ tab_results = self.table_ocr(tab_crop)
199
+ html_strings = []
200
+ for region in tab_results:
201
+ if region.get('type') == 'table' and 'res' in region:
202
+ html_strings.append(region['res'].get('html', ''))
203
+ ocr_content = "\n".join(html_strings)
204
+ ocr_confidence = None
205
+ print(f" -> Đã tự phục hồi và xử lý Table thành công đối tượng {i+1}!")
206
+ except Exception as reset_e:
207
+ print(f" -> [THẤT BẠI] Đã thử lại nhưng vẫn lỗi Table đối tượng {i+1}: {reset_e}")
208
+ ocr_content = "[Table Extractor Error]"
209
+ ocr_confidence = None
210
 
211
  elif class_name == "PartDrawing":
212
  # Không ocr part drawing