2024-8-5-midjourney共享版批量做图提交定时暂停手动暂停

由于midjourney手动提交1天搞下来大改只能收集150个图,非常疲惫而且会经历排队等待、队列占满导致的沮丧、进退两难。于是我想捣鼓一个自动提交的程序,经过这一天我大概看出来行为模式是用建筑装饰特征的图+楼面房型排列来实现建筑风格的生产。根据chatgpt的说法可以根据屏幕坐标来控制.exe文件中的/blend 命令实现自动化上传?我觉得可以试试看,用笔记本电脑全天开着自动匹配来生成素材?一方面是穷举几个文件夹中的图片排列组合使用/blend。还有一个是/imagine + 关键词,关键词应该是一个txt文件按照行来读取关键词,关键词提前准备好。还有一个是/describe + 图片链接,图片链接这一块通过selenium交互浏览器,批量抓取pinterest收藏的facade。

以下4天的进度跟踪是/blend的实现。主要依托pyautogui控制鼠标和键盘行为,遇到的难点有中文路径,自动暂停、手动暂停与任务执行时间关系、状态的计算。在这个过程中我觉得自动暂停、手动暂停控制执行任务的这个逻辑可以通用到其他日后类似需求的程序当中。另外就是制作程序时,遇到需要时长测试的先把任务部分简化为print输出,把时长放缩使周期缩短,这样能快速调试。当然这一整天的程序逻辑部分我丝毫没有去研究,完全就靠人工智能的概率论去蒙,做到了我理想状态的“我不懂,但我知道随心所欲”。

2024-8-1更新:用了一个上午实现了定时自动执行blend命令排列组合混合两个指定文件夹中所有的图片来尝试生产新的建筑装饰风格、部件。后来进一步实现了3个图的混合。需要注意的是这个程序可能每次打开窗口位置大小,文件对话框的位置不同需要修改代码中的各个pyautogui.click(x, y) 以适应变化从而能成功使程序点击定位对话框、方框、文件列表区域的位置。由于共享版不稳定可能会退出、封号什么的,我感觉自动搞半天需要查看一下最新进度,每次运行前测算一下运行时间为几个文件夹内的图片乘积再x任务间隔时间,我觉得间隔3分钟差不多,比如文件夹为4、3、5,那么就是4x3x5x3,180分钟3小时。这个程序放在笔记本电脑运行不干扰我正常主机的使用。

2024-8-2更新:完善了中文路径pyautogui无法输出的问题,利用pyperclip复制,然后pyautogui快捷键ctrl v黏贴输出的方式解决。midjourney输出图片的下载目前还不能完全自动化,需要一个个手动U键然后拉到最下面,单击图片选浏览器打开,用tabcopy批量复制浏览器所有标签页的图片地址,我试图用python程序批量下载但是遇到403 forbidden问题过不去,后来发现用WFDownloader这个软件支持对批量url下载,就不纠结咋解决python了。当生成的图多了,两次都碰到了在upscale时服务器自动消失的问题,暂时不知道原因,这样的话要和客服沟通去拿图有点麻烦,可能一次安排20轮1小时差不多可以了?一次生图太多不太好控制分析blend效果。

2024-8-4更新添加了按键监听功能,按p键可以暂停程序,这样可以保证一次设定长时间运行,不用分割好几个组多次重开,我觉得大概每过1小时左右暂停一下把生成的图下载,然后再开,时间太长了可能会导致之前的闪退问题。进一步添加了隔40分钟自动暂停,o键恢复继续任务,p键手动暂停/恢复任务。目前碰到的问题是图片生成完毕后逐个u按钮放大时可能遭遇服务器中的频道自动消失,目前原因不明,我想了下每过40分钟切换一个服务器重建新的频道再执行任务。进一步完善程序需要考虑计算自动暂停和手动暂停时所耗费的时间,今天还没来得及对修改后的代码做测试,明天测试间隔5分钟的自动暂停没问题之后改为40分钟。

2024-8-5经过一天的程序逻辑大改总算实现了,在面对这种有等待间隔测试复杂动作的程序为了要把等待间隔的逻辑搞正确应该先去掉复杂逻辑,然后压缩间隔周期来测试。不知不觉没想到用了5天才把这个程序给弄好。

midjourney共享版批量blend提交定时暂停手动暂停
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
  

import pyautogui
import schedule
import time
import os
from itertools import product
from datetime import datetime
import pyperclip
import sys
import keyboard # 需要安装 keyboard 库


# 配置
input_command1 = "/bl"
input_command2 = "end"

box1_position = (958, 643) # 方框1的位置
box2_position = (1142, 616) # 方框2的位置
box3_position = (1369, 648) # 方框3的位置(假设的位置,需要根据实际情况调整)
folder1_path = 'D:/midjourney相关/midjourney_PythonAuto/f1' # 文件夹1路径
folder2_path = 'D:/midjourney相关/midjourney_PythonAuto/f2' # 文件夹2路径
folder3_path = 'D:/midjourney相关/midjourney_PythonAuto/f3' # 文件夹3路径
file_delay = 1 # 文件选择的延迟时间(秒)

# 全局变量
index = 0
combinations = []
paused = False
auto_paused = False
last_active_time = time.time()
pause_start_time = None
auto_pause_start_time = None
total_pause_time = 0 # Total pause time (both manual and automatic)

# 获取当前时间的格式化字符串
def get_current_time():
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")

# 获取文件列表
def get_files(folder_path):
return [os.path.join(folder_path, file_name) for file_name in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, file_name))]

# 打开文件对话框并选择文件
def open_file_dialog_and_select_files(file_path, box_position):
print(f"{get_current_time()} - 打开文件对话框并选择文件:{file_path}") # 调试输出
pyautogui.click(box_position) # 点击方框以打开文件对话框
time.sleep(2) # 等待对话框打开

# 模拟打开文件对话框
pyautogui.hotkey('ctrl', 'l') # 将焦点移到地址栏
time.sleep(1)
pyperclip.copy(os.path.dirname(file_path))
time.sleep(1)
pyautogui.hotkey('ctrl', 'v') # 输入文件夹路径
pyautogui.press('enter') # 确认路径
time.sleep(1)
pyautogui.click(662, 643) # 点击文件列表区域
time.sleep(1)
pyperclip.copy(os.path.basename(file_path))
time.sleep(1)
pyautogui.hotkey('ctrl', 'v') # 输入文件名
time.sleep(1)
pyautogui.press('enter') # 选择文件
time.sleep(file_delay) # 等待文件加载

# 执行/blend命令
def execute_blend_command():
print(f"{get_current_time()} - 执行/blend命令") # 调试输出
time.sleep(2)
pyautogui.click(965, 853) # 点击输入框
pyautogui.typewrite(input_command1) # 输入命令
time.sleep(1)
pyautogui.typewrite(input_command2) # 输入额外的命令
pyautogui.press('enter') # 提交命令
time.sleep(1)
pyautogui.click(1315, 849)
time.sleep(1)
pyautogui.click(896, 433)
time.sleep(2) # 等待程序反应

# 初始化组合
def init_combinations():
global combinations
files1 = get_files(folder1_path)
files2 = get_files(folder2_path)
files3 = get_files(folder3_path)
combinations = list(product(files1, files2, files3))

# 执行任务
def task():
global index, paused, auto_paused, last_active_time, total_pause_time, auto_pause_start_time

current_time = time.time()
elapsed_time = current_time - last_active_time

if paused or auto_paused:
if auto_paused and auto_pause_start_time is None:
auto_pause_start_time = current_time # Record when auto pause started
return

if auto_pause_start_time is not None:
total_pause_time += current_time - auto_pause_start_time
auto_pause_start_time = None

active_time = elapsed_time - total_pause_time

# Check automatic pause condition
if active_time >= 120: # If active time exceeds 120 seconds, auto pause
auto_paused = True
print(f"{get_current_time()} - 自动暂停。\n\n")
return

if index < len(combinations):
file1, file2, file3 = combinations[index]
print(f"{get_current_time()} - 处理组合:{os.path.basename(file1)}{os.path.basename(file2)}{os.path.basename(file3)}") # 调试输出
execute_blend_command() # 执行/blend命令
open_file_dialog_and_select_files(file1, box1_position)
open_file_dialog_and_select_files(file2, box2_position)
open_file_dialog_and_select_files(file3, box3_position)
time.sleep(1)
pyautogui.press('enter') # 提交组合
time.sleep(1)
pyautogui.press('enter') # 提交组合
time.sleep(1) # 等待程序处理
index += 1
else:
print(f"{get_current_time()} - 所有组合已处理完成。") # 调试输出
schedule.cancel_job(job) # 取消定时任务
sys.exit()

# 手动暂停/恢复任务
def toggle_pause():
global paused, pause_start_time, total_pause_time, auto_pause_start_time
paused = not paused
if paused:
pause_start_time = time.time()
auto_pause_start_time = None
print(f"{get_current_time()} - 任务已暂停。\n\n")
else:
if pause_start_time is not None:
total_pause_time += time.time() - pause_start_time
pause_start_time = None
print(f"{get_current_time()} - 任务已继续。\n\n")

# 取消自动暂停
def continue_auto_pause():
global auto_paused, last_active_time, total_pause_time, auto_pause_start_time
auto_paused = False
last_active_time = time.time() # 重置计时器
total_pause_time = 0 # Reset total pause time
auto_pause_start_time = None # Reset auto pause start time
print(f"{get_current_time()} - 自动暂停已解除。\n\n")

# 监听键盘事件
def listen_keyboard():
keyboard.add_hotkey('p', toggle_pause) # 按下'p'键手动暂停/继续任务
keyboard.add_hotkey('o', continue_auto_pause) # 按下'o'键解除自动暂停

# 初始化组合
init_combinations()


# 定义定时任务
job = schedule.every(1.5).minutes.do(task) # 每1.5分钟执行一次任务

# 启动键盘监听
listen_keyboard()

while True:
schedule.run_pending()
time.sleep(1)

2024-8-9-baidu文心一言批量提交图片解析 2024-7-26-pdf切分章节与自动批量下载kimi回复并整理

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×