Skip to content
This repository was archived by the owner on Aug 11, 2024. It is now read-only.

Commit a4344f4

Browse files
authored
Merge pull request #36 from xingren23/dev
publish comfyflowapp with endpoint
2 parents 262718f + 126de5a commit a4344f4

14 files changed

+660
-366
lines changed

.streamlit/config.toml

-6
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,6 @@ enableStaticServing = false
122122

123123

124124
[client]
125-
# Default: true
126-
caching = true
127-
128-
# Default: true
129-
displayEnabled = true
130-
131125
# Default: true
132126
showErrorDetails = true
133127

modules/__init__.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,15 @@ def get_comfy_client():
4141
return comfy_client
4242

4343
@st.cache_resource
44-
def get_inner_comfy_client():
44+
def get_inner_comfy_client(endpoint):
4545
logger.info("get_inner_comfy_client")
4646
from modules.comfyclient import ComfyClient
47-
server_addr = os.getenv('INNER_COMFYUI_SERVER_ADDR')
48-
comfy_client = ComfyClient(server_addr=server_addr)
47+
comfy_client = ComfyClient(server_addr=endpoint)
4948
return comfy_client
5049

51-
def check_inner_comfyui_alive():
50+
def check_inner_comfyui_alive(endpoint):
5251
try:
53-
get_inner_comfy_client().queue_remaining()
52+
get_inner_comfy_client(endpoint).queue_remaining()
5453
return True
5554
except Exception as e:
5655
logger.warning(f"check comfyui alive error, {e}")

modules/comfyclient.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ class ComfyClient:
1313
def __init__(self, server_addr) -> None:
1414
self.client_id = str(uuid.uuid4())
1515
self.server_addr = server_addr
16-
self.timeout = 5
1716
logger.info(f"Comfy client id: {self.client_id}")
1817

1918
def get_node_class(self):
2019
object_info_url = f"{self.server_addr}/object_info"
2120
logger.info(f"Got object info from {object_info_url}")
22-
resp = requests.get(object_info_url, timeout=3)
21+
resp = requests.get(object_info_url)
2322
if resp.status_code != 200:
2423
raise Exception(f"Failed to get object info from {object_info_url}")
2524
return resp.json()
@@ -33,7 +32,7 @@ def queue_remaining(self):
3332
"""
3433
url = f"{self.server_addr}/prompt"
3534
logger.info(f"Got remaining from {url}")
36-
resp = requests.get(url, timeout=self.timeout)
35+
resp = requests.get(url)
3736
if resp.status_code != 200:
3837
raise Exception(f"Failed to get queue from {url}")
3938
return resp.json()['exec_info']['queue_remaining']
@@ -42,7 +41,7 @@ def queue_prompt(self, prompt):
4241
p = {"prompt": prompt, "client_id": self.client_id}
4342
data = json.dumps(p).encode('utf-8')
4443
logger.info(f"Sending prompt to server, {self.client_id}")
45-
resp = requests.post(f"{self.server_addr}/prompt", data=data, timeout=self.timeout)
44+
resp = requests.post(f"{self.server_addr}/prompt", data=data)
4645
if resp.status_code != 200:
4746
raise Exception(f"Failed to send prompt to server, {resp.status_code}")
4847
return resp.json()
@@ -83,7 +82,11 @@ def gen_images(self, prompt, queue):
8382
return prompt_id
8483

8584
def _websocket_loop(self, prompt, queue):
86-
wc_connect = "ws://{}/ws?clientId={}".format(urlparse.urlparse(self.server_addr).netloc, self.client_id)
85+
urlresult = urlparse.urlparse(self.server_addr)
86+
if urlresult.scheme == "http":
87+
wc_connect = "ws://{}/ws?clientId={}".format(urlresult.netloc, self.client_id)
88+
elif urlresult.scheme == "https":
89+
wc_connect = "wss://{}/ws?clientId={}".format(urlresult.netloc, self.client_id)
8790
logger.info(f"Websocket connect url, {wc_connect}")
8891
ws = websocket.WebSocket()
8992
ws.connect(wc_connect)

modules/myapp_model.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
class MyAppModel:
2222
def __init__(self) -> None:
23-
self.db_conn = st.experimental_connection('comfyflow_db', type='sql')
23+
self.db_conn = st.connection('comfyflow_db', type='sql')
2424
self.app_talbe_name = 'my_apps'
2525
self._init_table()
2626
logger.debug(f"db_conn: {self.db_conn}, app_talbe_name: {self.app_talbe_name}")
@@ -85,15 +85,15 @@ def sync_apps(self, apps):
8585
def get_all_apps(self):
8686
with self.session as s:
8787
logger.info("get apps from db")
88-
sql = text(f'SELECT id, name, description, image, app_conf, api_conf, template, url, status FROM {self.app_talbe_name} order by id desc;')
88+
sql = text(f'SELECT id, name, description, image, app_conf, api_conf, endpoint, template, url, status, username FROM {self.app_talbe_name} order by id desc;')
8989
apps = s.execute(sql).fetchall()
9090
return apps
9191

9292
def get_my_installed_apps(self):
9393
# get installed apps
9494
with self.session as s:
9595
logger.debug("get my apps from db")
96-
sql = text(f'SELECT id, name, description, image, app_conf, api_conf, template, url, status FROM {self.app_talbe_name} WHERE status=:status order by id desc;')
96+
sql = text(f'SELECT id, name, description, image, app_conf, api_conf, template, url, status, username FROM {self.app_talbe_name} WHERE status=:status order by id desc;')
9797
apps = s.execute(sql, {'status': AppStatus.INSTALLED.value}).fetchall()
9898
return apps
9999

modules/new_app.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ def process_image_edit(api_prompt):
114114
st.session_state['create_prompt'] =api_prompt
115115
inputs, outputs = parse_prompt(api_prompt)
116116
if inputs and outputs:
117-
logger.info(f"edit_prompt_inputs, {inputs}")
118-
st.session_state['edit_prompt_inputs'] = inputs
117+
logger.info(f"create_prompt_inputs, {inputs}")
118+
st.session_state['create_prompt_inputs'] = inputs
119119

120-
logger.info(f"edit_prompt_outputs, {outputs}")
121-
st.session_state['edit_prompt_outputs'] = outputs
120+
logger.info(f"create_prompt_outputs, {outputs}")
121+
st.session_state['create_prompt_outputs'] = outputs
122122

123123
st.success("parse workflow from image successfully")
124124
else:
@@ -330,8 +330,8 @@ def edit_app_ui(app):
330330

331331
with image_col2:
332332
image_icon = BytesIO(app.image)
333-
input_params = st.session_state.get('edit_prompt_inputs')
334-
output_params = st.session_state.get('edit_prompt_outputs')
333+
input_params = st.session_state.get('create_prompt_inputs')
334+
output_params = st.session_state.get('create_prompt_outputs')
335335
if image_icon and input_params and output_params:
336336
logger.debug(f"input_params: {input_params}, output_params: {output_params}")
337337
_, image_col, _ = st.columns([0.2, 0.6, 0.2])
@@ -373,6 +373,8 @@ def edit_app_ui(app):
373373
'help': param_help,
374374
}
375375
input_params.append(param)
376+
377+
logger.info(f"params_inputs_options {params_inputs_options}, input_params: {input_params}")
376378

377379
if len(input_params) > 0:
378380
input_param = input_params[0]
@@ -395,7 +397,7 @@ def edit_app_ui(app):
395397
with st.container():
396398

397399
st.markdown("Output Params:")
398-
params_outputs = st.session_state.get('edit_prompt_outputs', {})
400+
params_outputs = st.session_state.get('create_prompt_outputs', {})
399401
params_outputs_options = list(params_outputs.keys())
400402

401403
output_params = []

modules/page.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def change_mode_pages(mode):
1717
if mode == "Creator":
1818
pages = ['Home', 'Workspace', "My_Apps"]
1919
elif mode == "Explore":
20-
pages = ['Home', 'App_Store']
20+
pages = ['Home', 'App_Store', 'ComfyUI_Nodes']
2121
else:
2222
pages = [page['page_name'] for _, page in all_pages.items()]
2323
logger.info(f"pages: {pages}, mode: {mode}")

modules/preview_app.py

+2-25
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def preview_app_ui(app):
2828
if f"{name}_previewed" in st.session_state:
2929
previewed = st.session_state[f"{name}_previewed"]
3030
if previewed:
31-
st.success(f"Preview app {name} success, back to workspace, you could start or publish the app.")
31+
st.success(f"Preview app {name} success, you could install or publish the app at Workspace page.")
3232
get_workspace_model().update_app_preview(name)
3333
logger.info(f"update preview status for app: {name}")
3434
st.stop()
@@ -57,27 +57,4 @@ def enter_app_ui(app):
5757
app_data = app.app_conf
5858
comfy_client = get_comfy_client()
5959
comfyflow = Comfyflow(comfy_client=comfy_client, api_data=api_data, app_data=app_data)
60-
comfyflow.create_ui(show_header=False)
61-
62-
def on_back_store():
63-
st.session_state.pop('try_enter_app', None)
64-
logger.info("back to app store")
65-
66-
def try_enter_app_ui(app):
67-
with st.container():
68-
name = app.name
69-
description = app.description
70-
status = app.status
71-
logger.info(f"try app {name}, status: {status}")
72-
73-
with page.stylable_button_container():
74-
header_row = row([0.85, 0.15], vertical_align="top")
75-
header_row.title(f"{name}")
76-
header_row.button("App Store", help="Back to app store", key='try_back_store', on_click=on_back_store)
77-
78-
st.markdown(f"{description}")
79-
api_data = app.api_conf
80-
app_data = app.app_conf
81-
comfy_client = get_inner_comfy_client()
82-
comfyflow = Comfyflow(comfy_client=comfy_client, api_data=api_data, app_data=app_data)
83-
comfyflow.create_ui(show_header=False)
60+
comfyflow.create_ui(show_header=False)

0 commit comments

Comments
 (0)