-
最近由于工作的原因接触到了RPA,这是一种能够帮助人解决重复流程,提高效率的工具,刚好又接触到了AI绘画,想着把RPA和AI绘画融合到一起,那不是我上班的时候直接在家里跑图,晚上回家直接看个爽。思路有了,说干就干。*
本篇文章需要了解的内容有:SD的本地部署,RPA操作Excel写入表单,一点简单的python描述词的生成。
我使用的是某也的RPA,刚好里面有一个Excel数据写入表单的实例,直接拿来改改。
我将任务分为以下三个部分:
-
数据获取并写入Excel
-
rpa自动操作,将数据填入表单
-
模拟操作,生成图片
因为是初学刚开始,所以数据的获取我才用了手动获取,先去各种AI模型库找到想要的AI模型,下载并导入SD,在模型区和返图区会有一些大神的图片,获取其描述词。数据这一步就完成了。
下面是几个AI模型网站和一些描述词。
获取到这些文本,找到AI大兄弟叫他帮我写个代码,处理一下生成excel.
import random
import openpyxl
#数据的获取 最好是用自动化爬虫存到数据库中
#数据的清洗 主要是数据的分割 正负相关词是重点
# Define model names list
model_names = ["Model 1", "Model 2", "Model 3", "Model 4", "Model 5"]
# Define positive and negative keywords arrays
pos_keywords = ["keyword1", "keyword2", "keyword3", "keyword4", "keyword5"]
neg_keywords = ["keyword6", "keyword7", "keyword8", "keyword9", "keyword10"]
# Define sampling methods list
sampling_methods = ["Random Sampling", "Stratified Sampling", "Cluster Sampling"]
# Create new Excel workbook
wb = openpyxl.Workbook()
# Select the active worksheet
sheet = wb.active
# Set header row
sheet["A1"] = "模型名称"
sheet["B1"] = "正向关键词"
sheet["C1"] = "负向关键词"
sheet["D1"] = "采样方法"
sheet["E1"] = "步长"
# Fill data rows
for row in range(2, 102):
# Set model name
model_name = random.choice(model_names)
sheet.cell(row=row, column=1).value = model_name
# Set positive and negative keywords
pos_kw = random.sample(pos_keywords, k=random.randint(1, 5))
neg_kw = random.sample(neg_keywords, k=random.randint(1, 5))
pos_kw_str = ", ".join(pos_kw)
neg_kw_str = ", ".join(neg_kw)
sheet.cell(row=row, column=2).value = pos_kw_str
sheet.cell(row=row, column=3).value = neg_kw_str
# Set sampling method
sampling_method = random.choice(sampling_methods)
sheet.cell(row=row, column=4).value = sampling_method
# Set step size
step_size = random.randint(20, 30)
sheet.cell(row=row, column=5).value = step_size
# Save the workbook
wb.save("my_excel_file.xlsx")
OK完美解决第一个问题,我这里循环了一百次。
第二打开RPA的示例,一顿啪啪啪修改。
实现正向输入词,负向输入词,步长,生成按钮的模拟操作。
关于采样方法和模型选择上,我未实现,待定。基本已经完成自动化生成的基本目标。
管他有用没用,先跑起来。
经过两天的实验发现,实现了这个流程,但画出来的图并没有特别好的,但可以借鉴。因为生成的图片都是随机的,在随机选取关键词这个点,需要思考如何选取最合适的关键词。目前我采用的是保留前三到五个关键词,后面的关键词随机选取词库中的数据。
最后是一些生成的图片: