Skip to content

Commit 2ce75e4

Browse files
committed
update
1 parent 890ff1a commit 2ce75e4

File tree

4 files changed

+34
-43
lines changed

4 files changed

+34
-43
lines changed

TempImage/readme.jpg

66.3 KB
Loading

help.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,3 @@
8080
}
8181
}
8282
help_msg_all = [help_msg1,help_msg2,help_msg3,help_msg4,help_msg5]
83-
84-
85-
86-

readme.md

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,45 @@
11
# AI_SETU
22

3-
> 2022/11/10 21:00 更新内容:以图绘图改为使用stable diffusion UI的api
4-
>
5-
> 2022/10/24 20: 00 更新内容:合并今日少女插件(deemo)
6-
>
7-
> 2022/10/22 23: 40 更新内容:添加help.py,拆分文件
8-
>
9-
> 2022/10/22 15: 20 更新内容:使用yaml作为配置文件,拆分文件
10-
>
11-
> 2022/10/21 12:30 更新内容:动漫化指令,元素魔典逻辑修改
12-
>
13-
> 2022/10/18 18:56 更新内容:元素魔典原型指令,重新config.py添加轮询机制
14-
>
15-
> 2022/10/17 18:55 更新内容:图片相关指令均可通过回复触发,重写config.py,重写pic超分,重写图片鉴赏
16-
>
17-
> 2022/10/16 18:47 更新内容:更新pic超分相关内容,重写config.py
18-
>
19-
> 2022/10/13 18:47 更新内容:把一些看着难看的函数合并到until.py,查看pic添加每页最大参数
20-
>
21-
> 2022/10/11 21:47 更新内容:pic的上传,查看,点赞
3+
![效果图](TempImage/readme.jpg)
224

235
### **介绍**
246

25-
利用路路佬的API,实现HoshinoBot快速进行AI绘图
7+
利用[Stable Diffusion web UI](https://github.com/AUTOMATIC1111/stable-diffusion-webui) 的api 或是路路提供的友情api来实现**HoshinoBot**快速进行AI绘图
268

27-
快捷调用huggingface的仓库和开源模型
28-
29-
### 额外依赖
30-
31-
hjson,pyahocorasick,pyyaml
9+
额外提供快捷调用huggingface的某几个特定仓库和开源模型的方法
3210

3311
### 使用方法
3412

35-
- 装额外依赖
13+
- 装额外依赖 `hjson`,`pyahocorasick`,`pyyaml`,`aiofiles`
14+
15+
```
16+
pip install XXX
17+
```
3618
- 命令行输入
3719

3820
```
3921
cp config_example.yaml config.yaml
4022
```
4123

42-
然后自行修改 `config.yaml`
24+
然后根据注释提示自行修改 `config.yaml`
4325

4426
### 功能
4527

46-
* **绘图**
47-
* **以图绘图**
28+
* **(SD)绘图**
29+
* **(SD)以图绘图**
4830
* **个人/本群XP排行/缝合**
4931
* **上传pic**
5032
* **查看本群/个人/全部pic**
5133
* **点赞/删除pic**
5234
* **超分pic x倍超分 [保守/不]降噪 X为2,3,4 []内为可选参数**
5335
* **鉴赏图片**
5436
* **动漫化**
55-
* **元素法典吟唱**
56-
* **今天我是什么少女**
37+
* **(SD)元素法典吟唱**
38+
* **(SD)今天我是什么少女**
39+
40+
前缀含有**SD**则使用[Stable Diffusion web UI](https://github.com/AUTOMATIC1111/stable-diffusion-webui) 的api
41+
42+
无前缀默认使用路路提供的友情api
43+
44+
45+
**PS:渣代码,欢迎提出改进建议~**

until.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ async def process_tags(gid,uid,tags,add_db=config['add_db'],trans=config['trans'
7979
try:
8080
tags = f"tags={tags.strip().lower()}" #去除首尾空格换行#转小写#头部加上tags= #转小写方便处理
8181
taglist = re.split('&',tags) #分割
82-
id = ["tags=","ntags=","seed=","scale=","shape=","strength=","r18=","steps=","sampler=","restore_faces=","tiling="]
82+
id = ["tags=","ntags=","seed=","scale=","shape=","strength=","r18=","steps=","sampler=","restore_faces=","tiling=","bigger="]
8383
tag_dict = {i: ("" if not [idx for idx in taglist if idx.startswith(i)] else [idx for idx in taglist if idx.startswith(i)][-1]).replace(i, '', 1) for i in id }#取出tags+ntags+seed+scale+shape,每种只取列表最后一个,并删掉id
8484
except Exception as e:
8585
error_msg = f"tags初始化失败{e}"
@@ -141,6 +141,7 @@ async def process_tags(gid,uid,tags,add_db=config['add_db'],trans=config['trans'
141141
tag_dict["restore_faces="] = False#默认restore_faces
142142
if not tag_dict["tiling="] and tag_dict["tiling="] != "True":
143143
tag_dict["tiling="] = False#默认tiling
144+
tag_dict["bigger="] = False if not tag_dict["bigger="] else True#默认bigger
144145
#上传XP数据库
145146
if add_db:
146147
try:
@@ -208,6 +209,8 @@ async def get_imgdata_sd(tagdict:dict,way=1,shape="Portrait",b_io=None,size = No
208209
width,height = 768,512
209210
elif shape == "Square":
210211
width,height = 640,640
212+
if tagdict["bigger="]:
213+
width,height = width+128,height+128
211214
url = f"{config['sd_api_ip']}/sdapi/v1/txt2img"
212215
json_data = {
213216
"enable_hr": False,
@@ -227,6 +230,15 @@ async def get_imgdata_sd(tagdict:dict,way=1,shape="Portrait",b_io=None,size = No
227230
url = f"{config['sd_api_ip']}/sdapi/v1/img2img"
228231
data = ["data:image/jpeg;base64," + base64.b64encode(b_io.getvalue()).decode()]
229232
width,height = size
233+
if tagdict["bigger="]:
234+
width,height = width*2,height*2
235+
c = width/height
236+
n = 1000000 #最大像素
237+
if width*height > n:
238+
height = math.ceil(math.sqrt(n/c))
239+
width = math.ceil(c*height)
240+
width = math.ceil(width/64)*64
241+
height = math.ceil(height/64)*64 #等比缩放为64的倍数
230242
if not tagdict["strength="]:
231243
tagdict["strength="] = config['strength_moren']#默认噪声
232244
json_data = {
@@ -353,7 +365,7 @@ async def get_xp_pic_(msg,gid,uid):
353365
async def get_pic_d(msg):
354366
error_msg = "" # 报错信息
355367
try:
356-
image_url = re.search(r"\[CQ:image,file=(.*)url=(.*?)[,|\]]", str(msg))
368+
image_url = re.search(r"\[CQ:image,file=(.*)url=(.*?)[,\];]", str(msg))
357369
url = image_url.group(2)
358370
except Exception as e:
359371
error_msg = "你的图片呢?"
@@ -364,12 +376,6 @@ async def get_pic_d(msg):
364376
a,b = image.size
365377
c = a/b
366378
s = [0.6667,1.5,1]
367-
n = 1000000 #最大像素
368-
if a*b > n:
369-
b = math.ceil(math.sqrt(n/c))
370-
a = math.ceil(c*b)
371-
a = math.ceil(a/64)*64
372-
b = math.ceil(b/64)*64 #等比缩放为64的倍数
373379
size = (a,b)
374380
s1 =["Portrait","Landscape","Square"]
375381
shape=s1[s.index(nsmallest(1, s, key=lambda x: abs(x-c))[0])]#判断形状

0 commit comments

Comments
 (0)