diff --git a/Rayko_Image_Prompt.py b/Rayko_Image_Prompt.py index 82a2aee..01401af 100644 --- a/Rayko_Image_Prompt.py +++ b/Rayko_Image_Prompt.py @@ -35,11 +35,6 @@ def get_image_files(): files.sort() return files - -# ========================================================= -# Граф ComfyUI, чанк "prompt" (API-формат) -# ========================================================= - def _get_text_from_node(prompt_data, node_id, visited): node_id = str(node_id) if node_id in visited or node_id not in prompt_data: @@ -50,7 +45,6 @@ def _get_text_from_node(prompt_data, node_id, visited): inputs = node.get("inputs", {}) class_type = node.get("class_type", "") - # RS Prompts: если включён и подключён text_input — идём вверх по нему if inputs.get("enable_text_input"): ti = inputs.get("text_input") if isinstance(ti, list) and len(ti) >= 1: @@ -58,25 +52,21 @@ def _get_text_from_node(prompt_data, node_id, visited): if upstream: return upstream - # Прямой виджет "text" (только если это строка, а не ссылка) text = inputs.get("text") if isinstance(text, str) and text: return text - # RS_ImagePrompt: промпт в виджете "prompt_preview" if class_type == "RS_ImagePrompt": prompt_preview = inputs.get("prompt_preview") if isinstance(prompt_preview, str) and prompt_preview: return prompt_preview - # PromptStashPassthrough: если use_input_text=false — берём prompt_text if class_type == "PromptStashPassthrough": if not inputs.get("use_input_text", False): prompt_text = inputs.get("prompt_text") if isinstance(prompt_text, str) and prompt_text: return prompt_text - # Идём глубже по типичным входам (только если это ссылки, а не строки) for key in ("conditioning", "conditioning_1", "conditioning_2", "clip", "text_input", "text"): ref = inputs.get(key) if isinstance(ref, list) and len(ref) >= 1: @@ -98,7 +88,6 @@ def _extract_prompt_from_dict(prompt_data): if isinstance(ref, list) and len(ref) >= 1: negative_refs.add((str(ref[0]), ref[1] if len(ref) > 1 else 0)) - # Проход 1: от сэмплера по positive-связи for node_id, node_data in prompt_data.items(): if not isinstance(node_data, dict): continue @@ -110,7 +99,6 @@ def _extract_prompt_from_dict(prompt_data): if text: return text - # Проход 2 (фолбэк): известные промпт-ноды, кроме негативных for node_id, node_data in prompt_data.items(): if not isinstance(node_data, dict): continue @@ -143,11 +131,6 @@ def _extract_prompt(prompt_json_str): return "" return _extract_prompt_from_dict(data) - -# ========================================================= -# Граф ComfyUI, чанк "workflow" (UI-формат) — запасной -# ========================================================= - def _extract_prompt_from_workflow(workflow_json_str): try: wf = json.loads(workflow_json_str) @@ -215,11 +198,6 @@ def _extract_prompt_from_workflow(workflow_json_str): return t return "" - -# ========================================================= -# Сырые текстовые ключи (text / string / parameters / ...) -# ========================================================= - def _looks_like_settings(line): keys = ("Steps:", "Sampler:", "CFG scale:", "Seed:", "Size:", "Model hash:", "Model:", "Denoising strength:", "Clip skip:", "ENSAM:", "TI_hashes:") @@ -250,11 +228,6 @@ def _clean_text_prompt(text): lines.pop() return "\n".join(lines).strip() - -# ========================================================= -# EXIF UserComment (A1111 JPG / WebP) -# ========================================================= - def _decode_user_comment(data): if isinstance(data, str): return data @@ -292,11 +265,6 @@ def _extract_a1111_from_exif(pil_img): print(f"[RS Image-Prompt] EXIF error: {e}") return "" - -# ========================================================= -# Главная точка входа -# ========================================================= - def extract_prompt_from_file(input_path): try: with Image.open(input_path) as pil_img: @@ -306,21 +274,18 @@ def extract_prompt_from_file(input_path): print(f"[RS Image-Prompt] Cannot open image: {e}") return "" - # 1) ComfyUI API-граф prompt_json = info.get("prompt", "") if prompt_json: result = _extract_prompt(prompt_json) if result: return result - # 2) ComfyUI UI-граф workflow_json = info.get("workflow", "") if workflow_json: result = _extract_prompt_from_workflow(workflow_json) if result: return result - # 3) Сырые текстовые ключи for key in TEXT_KEYS: value = info.get(key) if isinstance(value, str) and value.strip(): @@ -328,7 +293,6 @@ def extract_prompt_from_file(input_path): if result: return result - # 4) EXIF UserComment (A1111 JPG / WebP) if exif_text: result = _clean_text_prompt(exif_text) if result: @@ -337,7 +301,6 @@ def extract_prompt_from_file(input_path): return "" -# ---------- API-роут для мгновенного чтения в UI ---------- @PromptServer.instance.routes.get("/rayko/get_prompt") async def rayko_get_prompt(request): filename = request.rel_url.query.get("filename", "")