Skip to content

Commit 8cb9daa

Browse files
committed
更新图像处理模块,优化用户组权限配置解析,调整图像发送时的标题处理逻辑,重构工作流配置以提升可读性和灵活性。
1 parent e339693 commit 8cb9daa

3 files changed

Lines changed: 93 additions & 27 deletions

File tree

handlers/commands/image.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
from configparser import ConfigParser
23
from dataclasses import dataclass
34
from datetime import datetime, timedelta
45
from typing import Optional, List, Dict, Any, Tuple
@@ -199,7 +200,7 @@ class PermissionManager:
199200
"""权限管理类"""
200201

201202
@staticmethod
202-
def parse_user_groups_config(config: Dict[str, Any]) -> Tuple[List[int], List[int]]:
203+
def parse_user_groups_config(config: ConfigParser) -> Tuple[List[int], List[int]]:
203204
"""解析用户和群组权限配置"""
204205
try:
205206
users = [int(i) for i in config["image"]["users"].split(",") if i.strip()]
@@ -602,11 +603,15 @@ async def handle_completed_task(task: Task, endpoint: str, prefix: str, rdb):
602603
text=f"Size: {size} Step: {step} Cost: {cost.total_seconds():.1f}s",
603604
)
604605

606+
caption = ""
607+
if task.msg.reply_content:
608+
caption = task.msg.reply_content[:1023]
609+
605610
await manager.bot.send_photo(
606611
chat_id=task.msg.chat_id,
607612
photo=input_file,
608613
reply_to_message_id=task.msg.message_id,
609-
caption=task.msg.reply_content[:1023],
614+
caption=caption,
610615
reply_markup=types.InlineKeyboardMarkup(inline_keyboard=[[types.InlineKeyboardButton(text="Original|原始图片", url=image_url)]]),
611616
)
612617
else:

utils/comfy_api.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ def create_workflow(
8686
Returns:
8787
工作流配置字典
8888
"""
89-
if seed is None:
90-
seed = random.randint(*DEFAULT_SEED_RANGE)
91-
9289
if checkpoint not in WORKFLOWS:
9390
checkpoint = "flux"
9491

@@ -100,13 +97,13 @@ def create_workflow(
10097
if checkpoint == "flux":
10198
workflow["6"]["inputs"]["text"] = prompt
10299
workflow["17"]["inputs"]["steps"] = steps
103-
workflow["27"]["inputs"]["width"] = width
104-
workflow["27"]["inputs"]["height"] = height
105-
workflow["30"]["inputs"]["width"] = width
106-
workflow["30"]["inputs"]["height"] = height
107-
workflow["27"]["inputs"]["batch_size"] = 1
108-
workflow["27"]["inputs"]["noise_seed"] = seed
109-
workflow["26"]["inputs"]["guidance"] = cfg
100+
# workflow["27"]["inputs"]["width"] = width
101+
# workflow["27"]["inputs"]["height"] = height
102+
# workflow["30"]["inputs"]["width"] = width
103+
# workflow["30"]["inputs"]["height"] = height
104+
# workflow["27"]["inputs"]["batch_size"] = 1
105+
# workflow["27"]["inputs"]["noise_seed"] = seed
106+
# workflow["26"]["inputs"]["guidance"] = cfg
110107

111108
return workflow
112109

utils/comfy_workflow.py

Lines changed: 79 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,77 @@
11
WORKFLOWS = {
22
"flux": {
3-
"6": {"inputs": {"text": "", "clip": ["44", 0]}, "class_type": "CLIPTextEncode", "_meta": {"title": "CLIP Text Encode (Positive Prompt)"}},
4-
"8": {"inputs": {"samples": ["13", 0], "vae": ["10", 0]}, "class_type": "VAEDecode", "_meta": {"title": "VAE Decode"}},
5-
"10": {"inputs": {"vae_name": "ae.safetensors"}, "class_type": "VAELoader", "_meta": {"title": "Load VAE"}},
3+
"6": {
4+
"inputs": {
5+
"text": "",
6+
"clip": ["44", 0],
7+
},
8+
"class_type": "CLIPTextEncode",
9+
"_meta": {"title": "CLIP Text Encode (Positive Prompt)"},
10+
},
11+
"8": {
12+
"inputs": {"samples": ["13", 0], "vae": ["10", 0]},
13+
"class_type": "VAEDecode",
14+
"_meta": {"title": "VAE Decode"},
15+
},
16+
"10": {
17+
"inputs": {"vae_name": "ae.safetensors"},
18+
"class_type": "VAELoader",
19+
"_meta": {"title": "Load VAE"},
20+
},
621
"13": {
7-
"inputs": {"noise": ["25", 0], "guider": ["22", 0], "sampler": ["16", 0], "sigmas": ["17", 0], "latent_image": ["27", 0]},
22+
"inputs": {
23+
"noise": ["25", 0],
24+
"guider": ["22", 0],
25+
"sampler": ["16", 0],
26+
"sigmas": ["17", 0],
27+
"latent_image": ["27", 0],
28+
},
829
"class_type": "SamplerCustomAdvanced",
930
"_meta": {"title": "SamplerCustomAdvanced"},
1031
},
11-
"16": {"inputs": {"sampler_name": "euler_ancestral"}, "class_type": "KSamplerSelect", "_meta": {"title": "KSamplerSelect"}},
32+
"16": {
33+
"inputs": {"sampler_name": "euler_ancestral"},
34+
"class_type": "KSamplerSelect",
35+
"_meta": {"title": "KSamplerSelect"},
36+
},
1237
"17": {
13-
"inputs": {"scheduler": "sgm_uniform", "steps": 16, "denoise": 1, "model": ["30", 0]},
38+
"inputs": {
39+
"scheduler": "sgm_uniform",
40+
"steps": 16,
41+
"denoise": 1,
42+
"model": ["30", 0],
43+
},
1444
"class_type": "BasicScheduler",
1545
"_meta": {"title": "BasicScheduler"},
1646
},
17-
"22": {"inputs": {"model": ["30", 0], "conditioning": ["26", 0]}, "class_type": "BasicGuider", "_meta": {"title": "BasicGuider"}},
18-
"25": {"inputs": {"noise_seed": 249566775388566}, "class_type": "RandomNoise", "_meta": {"title": "RandomNoise"}},
19-
"26": {"inputs": {"guidance": 2.1, "conditioning": ["6", 0]}, "class_type": "FluxGuidance", "_meta": {"title": "FluxGuidance"}},
20-
"27": {"inputs": {"width": 832, "height": 1216, "batch_size": 1}, "class_type": "EmptySD3LatentImage", "_meta": {"title": "EmptySD3LatentImage"}},
47+
"22": {
48+
"inputs": {"model": ["30", 0], "conditioning": ["26", 0]},
49+
"class_type": "BasicGuider",
50+
"_meta": {"title": "BasicGuider"},
51+
},
52+
"25": {
53+
"inputs": {"noise_seed": 733113376065330},
54+
"class_type": "RandomNoise",
55+
"_meta": {"title": "RandomNoise"},
56+
},
57+
"26": {
58+
"inputs": {"guidance": 2.1, "conditioning": ["6", 0]},
59+
"class_type": "FluxGuidance",
60+
"_meta": {"title": "FluxGuidance"},
61+
},
62+
"27": {
63+
"inputs": {"width": 832, "height": 1216, "batch_size": 1},
64+
"class_type": "EmptySD3LatentImage",
65+
"_meta": {"title": "EmptySD3LatentImage"},
66+
},
2167
"30": {
22-
"inputs": {"max_shift": 1.15, "base_shift": 0.5, "width": 832, "height": 1216, "model": ["47", 0]},
68+
"inputs": {
69+
"max_shift": 1.15,
70+
"base_shift": 0.5,
71+
"width": 832,
72+
"height": 1216,
73+
"model": ["47", 0],
74+
},
2375
"class_type": "ModelSamplingFlux",
2476
"_meta": {"title": "ModelSamplingFlux"},
2577
},
@@ -49,7 +101,11 @@
49101
"_meta": {"title": "Nunchaku FLUX DiT Loader"},
50102
},
51103
"47": {
52-
"inputs": {"lora_name": "flux/aidmaHyperrealism-FLUX-v0.3-[aidmaHyperrealism].safetensors", "lora_strength": 0.8, "model": ["55", 0]},
104+
"inputs": {
105+
"lora_name": "flux/aidmaHyperrealism-FLUX-v0.3-[aidmaHyperrealism].safetensors",
106+
"lora_strength": 0.8,
107+
"model": ["55", 0],
108+
},
53109
"class_type": "NunchakuFluxLoraLoader",
54110
"_meta": {"title": "Nunchaku FLUX LoRA Loader"},
55111
},
@@ -70,14 +126,22 @@
70126
"image_preview": True,
71127
"output_ext": ".webp",
72128
"quality": 90,
73-
"images": ["8", 0],
129+
"images": ["53", 0],
74130
},
75131
"class_type": "SaveImageExtended",
76132
"_meta": {"title": "💾 Save Image Extended"},
77133
},
78-
"53": {"inputs": {"value": ["8", 0]}, "class_type": "UnloadAllModels", "_meta": {"title": "UnloadAllModels"}},
134+
"53": {
135+
"inputs": {"value": ["8", 0]},
136+
"class_type": "UnloadAllModels",
137+
"_meta": {"title": "UnloadAllModels"},
138+
},
79139
"55": {
80-
"inputs": {"lora_name": "flux/flux1-turbo.safetensors", "lora_strength": 0.6, "model": ["45", 0]},
140+
"inputs": {
141+
"lora_name": "flux/flux1-turbo.safetensors",
142+
"lora_strength": 0.6,
143+
"model": ["45", 0],
144+
},
81145
"class_type": "NunchakuFluxLoraLoader",
82146
"_meta": {"title": "Nunchaku FLUX LoRA Loader"},
83147
},

0 commit comments

Comments
 (0)