SohomToom commited on
Commit
c586b29
·
verified ·
1 Parent(s): 18dde9e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -10,6 +10,8 @@ from paddleocr import PaddleOCR
10
  from PIL import Image
11
  import rarfile
12
  rarfile.UNRAR_TOOL = "unrar"
 
 
13
 
14
  ocr = PaddleOCR(use_angle_cls=True, lang='en', det_model_dir='models/det', rec_model_dir='models/rec', cls_model_dir='models/cls')
15
 
@@ -112,7 +114,7 @@ def remove_text_dynamic_fill(img_path, output_path):
112
 
113
  def process_cbz_cbr(files):
114
  final_output = tempfile.mkdtemp()
115
-
116
  for file_path in files:
117
  if file_path.endswith(".cbz"):
118
  with zipfile.ZipFile(file_path, 'r') as archive:
@@ -153,10 +155,21 @@ def convert_cbr_to_cbz(cbr_path):
153
  return cbz_path
154
 
155
 
 
 
 
 
 
 
 
 
 
 
156
  demo = gr.Interface(
157
  fn=process_cbz_cbr,
158
  inputs=gr.File(file_types=[".cbz"], file_count="multiple", label="Upload only .cbz Comic Files"),
159
  outputs=gr.File(label="Download Cleaned Zip"),
 
160
  title="Comic Cleaner from .CBZ",
161
  description="Upload .cbz comics. The app extracts, cleans (removes text), and gives back a zip of cleaned images."
162
  )
 
10
  from PIL import Image
11
  import rarfile
12
  rarfile.UNRAR_TOOL = "unrar"
13
+ import psutil
14
+ import time
15
 
16
  ocr = PaddleOCR(use_angle_cls=True, lang='en', det_model_dir='models/det', rec_model_dir='models/rec', cls_model_dir='models/cls')
17
 
 
114
 
115
  def process_cbz_cbr(files):
116
  final_output = tempfile.mkdtemp()
117
+ wait_for_cpu()
118
  for file_path in files:
119
  if file_path.endswith(".cbz"):
120
  with zipfile.ZipFile(file_path, 'r') as archive:
 
155
  return cbz_path
156
 
157
 
158
+ def wait_for_cpu(threshold=90, interval=3, timeout=30):
159
+ start = time.time()
160
+ while psutil.cpu_percent(interval=1) > threshold:
161
+ print("High CPU usage detected, waiting...")
162
+ time.sleep(interval)
163
+ if time.time() - start > timeout:
164
+ print("Timed out waiting for CPU to cool down.")
165
+ break
166
+
167
+
168
  demo = gr.Interface(
169
  fn=process_cbz_cbr,
170
  inputs=gr.File(file_types=[".cbz"], file_count="multiple", label="Upload only .cbz Comic Files"),
171
  outputs=gr.File(label="Download Cleaned Zip"),
172
+ concurrency_limit=1,
173
  title="Comic Cleaner from .CBZ",
174
  description="Upload .cbz comics. The app extracts, cleans (removes text), and gives back a zip of cleaned images."
175
  )