APIMONSTER commited on
Commit
1d550f3
·
verified ·
1 Parent(s): 3c9a517

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -0
app.py CHANGED
@@ -3,6 +3,8 @@ import re, json, tempfile
3
  import cv2
4
  import numpy as np
5
  import gradio as gr
 
 
6
  from ultralytics import YOLO
7
  from paddleocr import PaddleOCR
8
 
@@ -27,6 +29,10 @@ ocr = PaddleOCR(
27
  )
28
  # Force our exact char map (no dict file needed)
29
  ocr.text_recognizer.character = CHAR_LIST
 
 
 
 
30
 
31
  # ─── 4) Normalize & format OCR output
32
  def normalize_ocr(recs):
@@ -94,6 +100,9 @@ def run_image(img, conf=0.25):
94
 
95
  try:
96
  recs = ocr.ocr(warped, det=False, cls=True)
 
 
 
97
  except:
98
  recs = []
99
  txt, score = normalize_ocr(recs)
@@ -127,6 +136,9 @@ def run_video(video_file, conf=0.25):
127
 
128
  try:
129
  recs = ocr.ocr(warped, det=False, cls=True)
 
 
 
130
  except:
131
  recs = []
132
  txt, score = normalize_ocr(recs)
 
3
  import cv2
4
  import numpy as np
5
  import gradio as gr
6
+ import gc
7
+ import psutil
8
  from ultralytics import YOLO
9
  from paddleocr import PaddleOCR
10
 
 
29
  )
30
  # Force our exact char map (no dict file needed)
31
  ocr.text_recognizer.character = CHAR_LIST
32
+ def print_mem_usage(tag=""):
33
+ mem = psutil.virtual_memory()
34
+ print(f"[{tag}] RAM usage: {mem.used / 1024**2:.2f} MB / {mem.total / 1024**2:.2f} MB ({mem.percent}%)")
35
+
36
 
37
  # ─── 4) Normalize & format OCR output
38
  def normalize_ocr(recs):
 
100
 
101
  try:
102
  recs = ocr.ocr(warped, det=False, cls=True)
103
+ # After OCR call:
104
+ gc.collect()
105
+ print_mem_usage("After OCR")
106
  except:
107
  recs = []
108
  txt, score = normalize_ocr(recs)
 
136
 
137
  try:
138
  recs = ocr.ocr(warped, det=False, cls=True)
139
+ # After OCR call:
140
+ gc.collect()
141
+ print_mem_usage("After OCR")
142
  except:
143
  recs = []
144
  txt, score = normalize_ocr(recs)