Spaces:
Running
Running
rogerxavier
commited on
Commit
•
8bfda19
1
Parent(s):
60f04ce
Update utils.py
Browse files
utils.py
CHANGED
@@ -8,7 +8,7 @@ from config import *
|
|
8 |
import shutil
|
9 |
from PIL import Image#上传保存遮罩和比较遮罩width height能否和章节图片匹配的时候用
|
10 |
from taskMap import *
|
11 |
-
|
12 |
|
13 |
def load_config():
|
14 |
return get_variables()
|
@@ -117,6 +117,30 @@ def update_config_json(newConfig:str):
|
|
117 |
return content
|
118 |
|
119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
def is_asp_task_valid()->bool:
|
121 |
# 启动状态检测 ->
|
122 |
# 1config允许定时任务 2 mask目录下齐备 3 manga_all目录下有可用素材 4 mask的width height和素材匹配
|
@@ -124,7 +148,8 @@ def is_asp_task_valid()->bool:
|
|
124 |
# 6应该避免任务扎堆进行,对ocr space造成负担
|
125 |
print("判断任务条件时对config进行更新")
|
126 |
configData.update()
|
127 |
-
|
|
|
128 |
if configData.data['allow_scheduler'] == False:
|
129 |
print("当前配置不允许定时任务,停止定时任务")
|
130 |
return False
|
@@ -132,6 +157,9 @@ def is_asp_task_valid()->bool:
|
|
132 |
if cur_chapter == None:
|
133 |
print("当前没有可用章节了,停止定时任务")
|
134 |
return False
|
|
|
|
|
|
|
135 |
mask_file_path = os.path.join(configData.data['mask_dir'], '0.jpg')
|
136 |
if not os.path.exists(mask_file_path):
|
137 |
print("遮罩文件不存在,停止定时任务")
|
@@ -152,8 +180,9 @@ def is_asp_task_valid()->bool:
|
|
152 |
|
153 |
# 现在random_chapter_image中包含了选中的随机图片文件
|
154 |
if mask_image.size != random_chapter_image.size:
|
155 |
-
print("
|
156 |
-
|
|
|
157 |
else:
|
158 |
print("No image files found in the directory.")
|
159 |
return False
|
@@ -215,7 +244,7 @@ with gr.Blocks() as mangaManager:
|
|
215 |
def process_task_list(input_task_str:str = None,baseUrl:str =None):
|
216 |
if not is_asp_task_valid():
|
217 |
print("任务基本条件不符合")
|
218 |
-
|
219 |
return None
|
220 |
if baseUrl is None:
|
221 |
print("baseUrl不存在")
|
|
|
8 |
import shutil
|
9 |
from PIL import Image#上传保存遮罩和比较遮罩width height能否和章节图片匹配的时候用
|
10 |
from taskMap import *
|
11 |
+
from collections import Counter#计数删除少部分size不同图片
|
12 |
|
13 |
def load_config():
|
14 |
return get_variables()
|
|
|
117 |
return content
|
118 |
|
119 |
|
120 |
+
#void
|
121 |
+
def remove_different_size_images(chapter_path:str):
|
122 |
+
image_dir = chapter_path
|
123 |
+
# 获取目录下所有图片文件名
|
124 |
+
image_files = [f for f in os.listdir(image_dir) if os.path.isfile(os.path.join(image_dir, f))]
|
125 |
+
|
126 |
+
# 获取图片尺寸
|
127 |
+
image_sizes = []
|
128 |
+
for image_file in image_files:
|
129 |
+
with Image.open(os.path.join(image_dir, image_file)) as img:
|
130 |
+
image_sizes.append(img.size)
|
131 |
+
|
132 |
+
# 统计图片尺寸出现次数
|
133 |
+
size_counter = Counter(image_sizes)
|
134 |
+
|
135 |
+
# 找到占多数的章节图片尺寸
|
136 |
+
most_common_size = size_counter.most_common(1)[0][0]
|
137 |
+
|
138 |
+
# 删除其他尺寸的图片
|
139 |
+
for image_file, image_size in zip(image_files, image_sizes):
|
140 |
+
if image_size != most_common_size:
|
141 |
+
print("发现图片:",image_file,"大小不同于章节其他图片,认为是杂类图片,进行删除")
|
142 |
+
os.remove(os.path.join(image_dir, image_file))
|
143 |
+
|
144 |
def is_asp_task_valid()->bool:
|
145 |
# 启动状态检测 ->
|
146 |
# 1config允许定时任务 2 mask目录下齐备 3 manga_all目录下有可用素材 4 mask的width height和素材匹配
|
|
|
148 |
# 6应该避免任务扎堆进行,对ocr space造成负担
|
149 |
print("判断任务条件时对config进行更新")
|
150 |
configData.update()
|
151 |
+
|
152 |
+
|
153 |
if configData.data['allow_scheduler'] == False:
|
154 |
print("当前配置不允许定时任务,停止定时任务")
|
155 |
return False
|
|
|
157 |
if cur_chapter == None:
|
158 |
print("当前没有可用章节了,停止定时任务")
|
159 |
return False
|
160 |
+
print("开始删除当前chapter中部分size不同的少类图片")
|
161 |
+
remove_different_size_images(chapter_path=cur_chapter)
|
162 |
+
|
163 |
mask_file_path = os.path.join(configData.data['mask_dir'], '0.jpg')
|
164 |
if not os.path.exists(mask_file_path):
|
165 |
print("遮罩文件不存在,停止定时任务")
|
|
|
180 |
|
181 |
# 现在random_chapter_image中包含了选中的随机图片文件
|
182 |
if mask_image.size != random_chapter_image.size:
|
183 |
+
print("遮罩大小和章节随机图片的大小不匹配,继续定时任务,此处只做记录,因为前面已经删除了少类图片,且space也可以微调mask")
|
184 |
+
print("遮罩大小是:",mask_image.size,"随机章节图片大小是:",random_chapter_image.size)
|
185 |
+
return True
|
186 |
else:
|
187 |
print("No image files found in the directory.")
|
188 |
return False
|
|
|
244 |
def process_task_list(input_task_str:str = None,baseUrl:str =None):
|
245 |
if not is_asp_task_valid():
|
246 |
print("任务基本条件不符合")
|
247 |
+
|
248 |
return None
|
249 |
if baseUrl is None:
|
250 |
print("baseUrl不存在")
|