Update tab_comfy.py

This commit is contained in:
2026-01-02 20:50:53 +01:00
committed by GitHub
parent 7df798ccd1
commit a172fb5b15

View File

@@ -2,7 +2,7 @@ import streamlit as st
import requests import requests
from PIL import Image from PIL import Image
from io import BytesIO from io import BytesIO
from utils import save_config # <--- IMPORTED from utils import save_config
def render_single_instance(instance_config, index, all_instances): def render_single_instance(instance_config, index, all_instances):
url = instance_config.get("url", "http://127.0.0.1:8188") url = instance_config.get("url", "http://127.0.0.1:8188")
@@ -13,29 +13,25 @@ def render_single_instance(instance_config, index, all_instances):
c_head, c_set = st.columns([3, 1]) c_head, c_set = st.columns([3, 1])
c_head.markdown(f"### 🔌 {name}") c_head.markdown(f"### 🔌 {name}")
# --- SETTINGS POPOVER ---
with c_set.popover("⚙️ Settings"): with c_set.popover("⚙️ Settings"):
st.caption("Press Update to apply changes!") st.caption("Press Update to apply changes!")
new_name = st.text_input("Name", value=name, key=f"name_{index}") new_name = st.text_input("Name", value=name, key=f"name_{index}")
new_url = st.text_input("URL", value=url, key=f"url_{index}") new_url = st.text_input("URL", value=url, key=f"url_{index}")
# VISUAL WARNING if typed value differs from saved value
if new_url != url: if new_url != url:
st.warning("⚠️ Unsaved URL! Click Update below.") st.warning("⚠️ Unsaved URL! Click Update below.")
if st.button("💾 Update & Save", key=f"save_{index}", type="primary"): if st.button("💾 Update & Save", key=f"save_{index}", type="primary"):
# 1. Update Memory
all_instances[index]["name"] = new_name all_instances[index]["name"] = new_name
all_instances[index]["url"] = new_url all_instances[index]["url"] = new_url
st.session_state.config["comfy_instances"] = all_instances st.session_state.config["comfy_instances"] = all_instances
# 2. SAVE TO DISK (The Fix)
save_config( save_config(
st.session_state.current_dir, st.session_state.current_dir,
st.session_state.config['favorites'], st.session_state.config['favorites'],
{"comfy_instances": all_instances} {"comfy_instances": all_instances}
) )
st.toast("Server config saved to disk!", icon="💾") st.toast("Server config saved!", icon="💾")
st.rerun() st.rerun()
st.divider() st.divider()
@@ -71,26 +67,32 @@ def render_single_instance(instance_config, index, all_instances):
st.error(f"Could not connect to {COMFY_URL}") st.error(f"Could not connect to {COMFY_URL}")
return return
# --- 2. LIVE VIEW --- # --- 2. LIVE VIEW (WITH TOGGLE) ---
st.write("") st.write("")
c_label, c_slider = st.columns([1, 2]) c_label, c_ctrl = st.columns([1, 2])
c_label.subheader("📺 Live View") c_label.subheader("📺 Live View")
# Slider force-reloads the iframe (normal behavior) # LIVE PREVIEW TOGGLE
iframe_h = c_slider.slider( enable_preview = c_ctrl.checkbox("Enable Live Preview", value=True, key=f"live_toggle_{index}")
"Window Size (px)",
min_value=600, max_value=2500, value=1000, step=50, if enable_preview:
key=f"h_slider_{index}", label_visibility="collapsed" # Height Slider
) iframe_h = st.slider(
"Height (px)",
min_value=600, max_value=2500, value=1000, step=50,
key=f"h_slider_{index}"
)
st.markdown( st.markdown(
f""" f"""
<iframe src="{COMFY_URL}" width="100%" height="{iframe_h}px" <iframe src="{COMFY_URL}" width="100%" height="{iframe_h}px"
style="border: 1px solid #444; border-radius: 8px; box-shadow: 0 4px 6px rgba(0,0,0,0.3);"> style="border: 1px solid #444; border-radius: 8px; box-shadow: 0 4px 6px rgba(0,0,0,0.3);">
</iframe> </iframe>
""", """,
unsafe_allow_html=True unsafe_allow_html=True
) )
else:
st.info("Live Preview is disabled. Enable it above to see the interface.")
st.markdown("---") st.markdown("---")
@@ -152,7 +154,6 @@ def render_comfy_monitor():
instances.append({"name": new_name, "url": new_url}) instances.append({"name": new_name, "url": new_url})
st.session_state.config["comfy_instances"] = instances st.session_state.config["comfy_instances"] = instances
# SAVE TO DISK IMMEDIATELY
save_config( save_config(
st.session_state.current_dir, st.session_state.current_dir,
st.session_state.config['favorites'], st.session_state.config['favorites'],