- comfyui.env에 ENABLE_IMAGE_PROMPT_GENERATION=true - 이미지 설정 맞춤(python): 'Open WebUI와 연결'·처음 설정 때 image_generation.prompt.enable 기록 (평소 기동·재시작 때는 화면에서 바꾼 값을 그대로 둠) - 한국어 요청을 채팅 모델이 영어 그림 프롬프트로 다시 써서 ComfyUI로 보냄 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HnDmXrFqktWwYa1cuJRAVZ
148 lines
9.2 KiB
PowerShell
148 lines
9.2 KiB
PowerShell
# JJ Ollama Manager (Windows) — src/platform/windows/15_webui_image_sync.ps1 : Open WebUI 이미지 생성·편집 설정 (DB 맞춤)
|
|
# jj_ollama_manager.ps1 가 순서대로 불러옵니다 (직접 실행하지 않음). 2026-11-05 추가
|
|
|
|
# ---------- 이미지 편집 (그림 → 그림) ----------
|
|
$ComfyEditDenoise = 0.6 # 편집 강도: 0.3 = 원본 거의 그대로 · 0.6 = 기본 · 0.9 = 거의 새로 그림
|
|
|
|
# 편집용 작업흐름: 올린 그림(1) → 크기 맞춤(11) → 잠재 공간(10) → KSampler(3, denoise) → 저장(9)
|
|
# Open WebUI가 그림을 ComfyUI에 올린 뒤 그 파일 이름을 1번 노드 image 칸에 넣음
|
|
function Get-ComfyEditWorkflowJson($Preset) {
|
|
$cfg = ([string]$Preset.Cfg).Replace(',', '.')
|
|
$dn = ([string]$ComfyEditDenoise).Replace(',', '.')
|
|
$wf = '{"1":{"inputs":{"image":"example.png"},"class_type":"LoadImage"},' +
|
|
'"11":{"inputs":{"upscale_method":"lanczos","width":' + $Preset.W + ',"height":' + $Preset.H + ',"crop":"center","image":["1",0]},"class_type":"ImageScale"},' +
|
|
'"10":{"inputs":{"pixels":["11",0],"vae":["4",2]},"class_type":"VAEEncode"},' +
|
|
'"3":{"inputs":{"seed":0,"steps":' + $Preset.Steps + ',"cfg":' + $cfg + ',"sampler_name":"' + $Preset.Sampler + '","scheduler":"' + $Preset.Scheduler + '","denoise":' + $dn + ',"model":["4",0],"positive":["6",0],"negative":["7",0],"latent_image":["10",0]},"class_type":"KSampler"},' +
|
|
'"4":{"inputs":{"ckpt_name":"' + $Preset.File + '"},"class_type":"CheckpointLoaderSimple"},' +
|
|
'"6":{"inputs":{"text":"Prompt","clip":["4",1]},"class_type":"CLIPTextEncode"},' +
|
|
'"7":{"inputs":{"text":"low quality, blurry, bad anatomy, watermark, text","clip":["4",1]},"class_type":"CLIPTextEncode"},' +
|
|
'"8":{"inputs":{"samples":["3",0],"vae":["4",2]},"class_type":"VAEDecode"},' +
|
|
'"9":{"inputs":{"filename_prefix":"OpenWebUI_edit","images":["8",0]},"class_type":"SaveImage"}}'
|
|
return $wf
|
|
}
|
|
|
|
# 편집은 부정 프롬프트·단계를 넘기지 않으므로(Open WebUI) 그 두 가지는 연결하지 않음
|
|
$ComfyEditWorkflowNodes = '[{"type":"image","key":"image","node_ids":["1"]},{"type":"prompt","key":"text","node_ids":["6"]},{"type":"model","key":"ckpt_name","node_ids":["4"]},{"type":"width","key":"width","node_ids":["11"]},{"type":"height","key":"height","node_ids":["11"]},{"type":"seed","key":"seed","node_ids":["3"]}]'
|
|
|
|
# ---------- WebUI DB의 이미지 설정을 연결 설정 파일(comfyui.env)에 맞춤 ----------
|
|
# Open WebUI는 한 번 저장된 설정(webui.db)을 환경변수보다 먼저 씀 → env를 바꿔도 반영되지 않는 문제 대응
|
|
# 기본: 고장 난 값만 고침 (노드 ID가 비어 있음 / DB 주소로 ComfyUI 접속이 안 되고 env 주소는 됨 / 편집을 한 번도 설정하지 않음)
|
|
# -Force: env 값 전체를 DB에 씀 ('Open WebUI와 연결'에서 모델을 고를 때)
|
|
$WebuiImageSyncPy = @'
|
|
import os, sys, json, time, sqlite3, urllib.request
|
|
e = os.environ
|
|
force = e.get('JJ_FORCE') == '1'
|
|
db = sqlite3.connect(e.get('JJ_DB', '/app/backend/data/webui.db'), timeout=15)
|
|
def get(k):
|
|
r = db.execute('select value from config where key=?', (k,)).fetchone()
|
|
if not r: return None
|
|
v = r[0]
|
|
return json.loads(v) if isinstance(v, (str, bytes)) else v
|
|
def same(a, b):
|
|
try:
|
|
if isinstance(a, str) and isinstance(b, str) and a.strip()[:1] in '{[' and b.strip()[:1] in '{[':
|
|
return json.loads(a) == json.loads(b)
|
|
except Exception:
|
|
pass
|
|
return a == b
|
|
def ok(u):
|
|
if not u: return False
|
|
try:
|
|
return urllib.request.urlopen(u.rstrip('/') + '/system_stats', timeout=5).status == 200
|
|
except Exception:
|
|
return False
|
|
def jl(name):
|
|
try:
|
|
return json.loads(e.get(name) or '[]')
|
|
except Exception:
|
|
return []
|
|
def empty_ids(nodes, types):
|
|
for t in types:
|
|
m = [n for n in (nodes or []) if isinstance(n, dict) and n.get('type') == t]
|
|
if not m or not m[0].get('node_ids'):
|
|
return True
|
|
return False
|
|
want = {}
|
|
# 1) image generation (image_generation.*)
|
|
if e.get('IMAGE_GENERATION_ENGINE', '').lower() == 'comfyui':
|
|
nodes = jl('COMFYUI_WORKFLOW_NODES')
|
|
url = (e.get('COMFYUI_BASE_URL') or '').strip()
|
|
if force:
|
|
want['image_generation.enable'] = True
|
|
want['image_generation.engine'] = 'comfyui'
|
|
if e.get('ENABLE_IMAGE_PROMPT_GENERATION'): want['image_generation.prompt.enable'] = e['ENABLE_IMAGE_PROMPT_GENERATION'].lower() == 'true'
|
|
if e.get('IMAGE_GENERATION_MODEL'): want['image_generation.model'] = e['IMAGE_GENERATION_MODEL']
|
|
if e.get('IMAGE_SIZE'): want['image_generation.size'] = e['IMAGE_SIZE']
|
|
if (e.get('IMAGE_STEPS') or '').isdigit(): want['image_generation.steps'] = int(e['IMAGE_STEPS'])
|
|
if url: want['image_generation.comfyui.base_url'] = url
|
|
if e.get('COMFYUI_WORKFLOW'): want['image_generation.comfyui.workflow'] = e['COMFYUI_WORKFLOW']
|
|
if nodes: want['image_generation.comfyui.nodes'] = nodes
|
|
elif get('image_generation.engine') != 'comfyui' and not (get('image_generation.comfyui.workflow') or '').strip():
|
|
# never set up in WebUI yet (engine still default, no workflow) -> write all generation keys
|
|
want['image_generation.enable'] = True
|
|
want['image_generation.engine'] = 'comfyui'
|
|
if e.get('ENABLE_IMAGE_PROMPT_GENERATION'): want['image_generation.prompt.enable'] = e['ENABLE_IMAGE_PROMPT_GENERATION'].lower() == 'true'
|
|
if e.get('IMAGE_GENERATION_MODEL'): want['image_generation.model'] = e['IMAGE_GENERATION_MODEL']
|
|
if e.get('IMAGE_SIZE'): want['image_generation.size'] = e['IMAGE_SIZE']
|
|
if (e.get('IMAGE_STEPS') or '').isdigit(): want['image_generation.steps'] = int(e['IMAGE_STEPS'])
|
|
if url: want['image_generation.comfyui.base_url'] = url
|
|
if e.get('COMFYUI_WORKFLOW'): want['image_generation.comfyui.workflow'] = e['COMFYUI_WORKFLOW']
|
|
if nodes: want['image_generation.comfyui.nodes'] = nodes
|
|
else:
|
|
if nodes and empty_ids(get('image_generation.comfyui.nodes'), ['prompt']):
|
|
want['image_generation.comfyui.nodes'] = nodes
|
|
cur_url = get('image_generation.comfyui.base_url') or ''
|
|
if url and cur_url.strip() != url and not ok(cur_url) and ok(url):
|
|
want['image_generation.comfyui.base_url'] = url
|
|
# 2) image edit (images.edit.*)
|
|
if e.get('IMAGE_EDIT_ENGINE', '').lower() == 'comfyui':
|
|
enodes = jl('IMAGES_EDIT_COMFYUI_WORKFLOW_NODES')
|
|
eurl = (e.get('IMAGES_EDIT_COMFYUI_BASE_URL') or '').strip()
|
|
full = {'images.edit.enable': e.get('ENABLE_IMAGE_EDIT', '').lower() == 'true',
|
|
'images.edit.engine': 'comfyui'}
|
|
if e.get('IMAGE_EDIT_MODEL'): full['images.edit.model'] = e['IMAGE_EDIT_MODEL']
|
|
if e.get('IMAGE_EDIT_SIZE'): full['images.edit.size'] = e['IMAGE_EDIT_SIZE']
|
|
if eurl: full['images.edit.comfyui.base_url'] = eurl
|
|
if e.get('IMAGES_EDIT_COMFYUI_WORKFLOW'): full['images.edit.comfyui.workflow'] = e['IMAGES_EDIT_COMFYUI_WORKFLOW']
|
|
if enodes: full['images.edit.comfyui.nodes'] = enodes
|
|
if force or not (get('images.edit.comfyui.workflow') or '').strip():
|
|
want.update(full) # forced, or edit never set up in WebUI yet
|
|
else:
|
|
if enodes and empty_ids(get('images.edit.comfyui.nodes'), ['image', 'prompt']):
|
|
want['images.edit.comfyui.nodes'] = enodes
|
|
cur_eurl = get('images.edit.comfyui.base_url') or ''
|
|
if eurl and cur_eurl.strip() != eurl and not ok(cur_eurl) and ok(eurl):
|
|
want['images.edit.comfyui.base_url'] = eurl
|
|
if not want and e.get('IMAGE_GENERATION_ENGINE', '').lower() != 'comfyui' and e.get('IMAGE_EDIT_ENGINE', '').lower() != 'comfyui':
|
|
print('SKIP'); sys.exit(0)
|
|
# 3) function calling default for all users: legacy (Image switch -> straight to ComfyUI, works with models without tools)
|
|
# only when no global value is set yet (an admin choice like native is kept)
|
|
if e.get('IMAGE_GENERATION_ENGINE', '').lower() == 'comfyui':
|
|
dp = get('models.default_params')
|
|
dp = dict(dp) if isinstance(dp, dict) else {}
|
|
if not dp.get('function_calling'):
|
|
dp['function_calling'] = 'legacy'
|
|
want['models.default_params'] = dp
|
|
changed = [k for k, v in want.items() if not same(get(k), v)]
|
|
now = int(time.time())
|
|
for k in changed:
|
|
db.execute('insert into config(key, value, updated_at) values(?, ?, ?) '
|
|
'on conflict(key) do update set value=excluded.value, updated_at=excluded.updated_at',
|
|
(k, json.dumps(want[k], ensure_ascii=False), now))
|
|
db.commit()
|
|
print('CHANGED:' + ','.join(k.replace('image_generation.', '').replace('images.', '') for k in changed) if changed else 'OK')
|
|
'@
|
|
|
|
function Sync-WebuiImageConfig([switch]$Force) {
|
|
if (-not (Test-Path $WebuiEnvFile)) { return }
|
|
if ((Get-WebuiInfo).State -ne 'running') { return }
|
|
$f = if ($Force) { '1' } else { '0' }
|
|
$out = @($WebuiImageSyncPy | & $script:PodmanExe exec -i -e "JJ_FORCE=$f" $WebuiName python3 - 2>&1)
|
|
$last = "$($out | Select-Object -Last 1)".Trim()
|
|
if ($last -like 'CHANGED:*') {
|
|
Write-C "${GREEN}✅ WebUI 이미지 설정(DB)을 연결 설정에 맞췄습니다: $($last.Substring(8))${RESET}"
|
|
} elseif ($last -ne 'OK' -and $last -ne 'SKIP') {
|
|
Write-C "${YELLOW}⚠️ WebUI 이미지 설정(DB)을 확인하지 못했습니다: $last${RESET}"
|
|
}
|
|
}
|