Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -102,6 +102,9 @@ def remove_text_dynamic_fill(img_path, output_path):
|
|
| 102 |
|
| 103 |
def process_folder(input_files):
|
| 104 |
temp_output = tempfile.mkdtemp()
|
|
|
|
|
|
|
|
|
|
| 105 |
for file in input_files:
|
| 106 |
filename = os.path.basename(file.name)
|
| 107 |
output_path = os.path.join(temp_output, filename)
|
|
@@ -110,10 +113,23 @@ def process_folder(input_files):
|
|
| 110 |
zip_path = shutil.make_archive(temp_output, 'zip', temp_output)
|
| 111 |
return zip_path
|
| 112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
demo = gr.Interface(
|
| 114 |
fn=process_folder,
|
| 115 |
inputs=gr.File(file_types=[".jpg", ".jpeg", ".png"], file_count="multiple", label="Upload Comic Images"),
|
| 116 |
outputs=gr.File(label="Download Cleaned Zip"),
|
|
|
|
| 117 |
title="Comic Text Cleaner",
|
| 118 |
description="Upload comic images and get a zip of cleaned versions (text removed). Uses PaddleOCR for detection."
|
| 119 |
)
|
|
|
|
| 102 |
|
| 103 |
def process_folder(input_files):
|
| 104 |
temp_output = tempfile.mkdtemp()
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
wait_for_cpu();
|
| 108 |
for file in input_files:
|
| 109 |
filename = os.path.basename(file.name)
|
| 110 |
output_path = os.path.join(temp_output, filename)
|
|
|
|
| 113 |
zip_path = shutil.make_archive(temp_output, 'zip', temp_output)
|
| 114 |
return zip_path
|
| 115 |
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def wait_for_cpu(threshold=90, interval=3, timeout=30):
|
| 119 |
+
start = time.time()
|
| 120 |
+
while psutil.cpu_percent(interval=1) > threshold:
|
| 121 |
+
print("High CPU usage detected, waiting...")
|
| 122 |
+
time.sleep(interval)
|
| 123 |
+
if time.time() - start > timeout:
|
| 124 |
+
print("Timed out waiting for CPU to cool down.")
|
| 125 |
+
break
|
| 126 |
+
|
| 127 |
+
|
| 128 |
demo = gr.Interface(
|
| 129 |
fn=process_folder,
|
| 130 |
inputs=gr.File(file_types=[".jpg", ".jpeg", ".png"], file_count="multiple", label="Upload Comic Images"),
|
| 131 |
outputs=gr.File(label="Download Cleaned Zip"),
|
| 132 |
+
concurrency_limit=1,
|
| 133 |
title="Comic Text Cleaner",
|
| 134 |
description="Upload comic images and get a zip of cleaned versions (text removed). Uses PaddleOCR for detection."
|
| 135 |
)
|