itemaz commited on
Commit
cc3a411
·
verified ·
1 Parent(s): 07c1a37

Update summary/views.py

Browse files
Files changed (1) hide show
  1. summary/views.py +4 -16
summary/views.py CHANGED
@@ -49,7 +49,6 @@ def get_tool():
49
  def get_ocr():
50
  global _ocr_model
51
  if _ocr_model is None:
52
- print("🚀 Загрузка PaddleOCR...")
53
  from paddleocr import PaddleOCR
54
  _ocr_model = PaddleOCR(use_angle_cls=True, lang='ru', enable_mkldnn=False)
55
  return _ocr_model
@@ -136,21 +135,10 @@ def ocr_process(request):
136
  image_file = request.FILES.get('image')
137
  if not image_file: return JsonResponse({'error': 'Файл не найден'})
138
  try:
139
- file_bytes = image_file.read()
140
- nparr = np.frombuffer(file_bytes, np.uint8)
141
- img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
142
- img = limit_image_size(img)
143
-
144
- ocr = get_ocr()
145
  result = ocr.ocr(img)
146
-
147
- final_text_blocks = []
148
- if result and result[0]:
149
- for line in result[0]:
150
- final_text_blocks.append(line[1][0])
151
-
152
- import re
153
- clean_text = re.sub(r'\s+([,.!?;:])', r'\1', " ".join(final_text_blocks))
154
  return JsonResponse({'text': clean_text})
155
  except Exception as e:
156
- return JsonResponse({'error': f'Ошибка OCR: {str(e)}'})
 
49
  def get_ocr():
50
  global _ocr_model
51
  if _ocr_model is None:
 
52
  from paddleocr import PaddleOCR
53
  _ocr_model = PaddleOCR(use_angle_cls=True, lang='ru', enable_mkldnn=False)
54
  return _ocr_model
 
135
  image_file = request.FILES.get('image')
136
  if not image_file: return JsonResponse({'error': 'Файл не найден'})
137
  try:
138
+ # ... твой код декодирования картинки ...
139
+ ocr = get_ocr() # Вызываем загрузчик
 
 
 
 
140
  result = ocr.ocr(img)
141
+ # ... твой код сборки текста (оставь как был) ...
 
 
 
 
 
 
 
142
  return JsonResponse({'text': clean_text})
143
  except Exception as e:
144
+ return JsonResponse({'error': f'Ошибка OCR: {str(e)}'})