dmMaze / BallonsTranslator

深度学习辅助漫画翻译工具, 支持一键机翻和简单的图像/文本编辑 | Yet another computer-aided comic/manga translation tool powered by deeplearning
GNU General Public License v3.0
2.48k stars 172 forks source link

feat: Added a command-line instruction for batch translation of content within subfolders. #520

Closed caiweihan closed 1 month ago

caiweihan commented 1 month ago

For a folder that contains multiple subfolders, where each subfolder includes various comic images, you can use this command to batch process all subfolders:

python script.py --exec-subfolders "[DIR]"

For this feature, I've added some lines of code in launch.py:

parser.add_argument("--exec-subfolders", default='', type=str, help='Folder containing subdirectories to be added to --exec_dirs')
...
if args.exec_subfolders:
    subfolders = [os.path.join(args.exec_subfolders, d) for d in os.listdir(args.exec_subfolders) if os.path.isdir(os.path.join(args.exec_subfolders, d))]
    args.exec_dirs = ','.join(subfolders)

You can also use this command for translation, which will bring up the interface and display the images being translated in real-time, providing a better demonstration of the progress and accuracy of the translations:

python launch.py --exec_dirs "[DIR_1],[DIR_2]..."

I have modified the code in the __init__ function of mainwindow.py from:

if shared.HEADLESS:
    self.run_batch(**exec_args)

to:

self.run_batch(**exec_args)

And changed the code in the on_imgtrans_pipeline_finished function from:

if shared.HEADLESS:
    self.run_next_dir()

to:

self.run_next_dir()

In addition, I have updated the README files to inform users about these new features.

dmMaze commented 1 month ago

I have modified the code in the __init__ function of mainwindow.py from:

if shared.HEADLESS:
    self.run_batch(**exec_args)

to:

self.run_batch(**exec_args)

这样改有个问题是不传 exec 相关参数的时候下面的判断会直接让程序退出,可以

  1. 在 run_batch 里检查发现 exec 相关参数为空且 headless 模式就在调用 run_next_dir 前返回
  2. 下面的条件 if len(self.exec_dirs) == 0: 改成 if len(self.exec_dirs) == 0 and shared.HEADLESS:

https://github.com/dmMaze/BallonsTranslator/blob/82d2df2735933070fcfa245d7773619b9a227005/ui/mainwindow.py#L1244C1-L1248C19

为什么要额外加个 argument,直接对每个 exec_dirs 递归找下一层目录就行了,是否递归可以加个可选参数 --recursive 。 另外找下一层目录的时候最好滤掉 basename 是 inpainted, result, mask 这些存结果的目录。

另外建议不要在 launch.py 而是在 run_batch 里面解析执行参数。

caiweihan commented 1 month ago

I have modified the code in the __init__ function of mainwindow.py from:

if shared.HEADLESS:
    self.run_batch(**exec_args)

to:

self.run_batch(**exec_args)

这样改有个问题是不传 exec 相关参数的时候下面的判断会直接让程序退出,可以

  1. 在 run_batch 里检查发现 exec 相关参数为空且 headless 模式就在调用 run_next_dir 前返回
  2. 下面的条件 if len(self.exec_dirs) == 0: 改成 if len(self.exec_dirs) == 0 and shared.HEADLESS:

https://github.com/dmMaze/BallonsTranslator/blob/82d2df2735933070fcfa245d7773619b9a227005/ui/mainwindow.py#L1244C1-L1248C19

为什么要额外加个 argument,直接对每个 exec_dirs 递归找下一层目录就行了,是否递归可以加个可选参数 --recursive 。 另外找下一层目录的时候最好滤掉 basename 是 inpainted, result, mask 这些存结果的目录。

另外建议不要在 launch.py 而是在 run_batch 里面解析执行参数。

OK,这是我昨天遇到 Qt 的问题后自己让程序能够运行而改的代码,那就不提交了吧