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

Commit

Permalink
Merge pull request #36 from xingren23/dev
Browse files Browse the repository at this point in the history
publish comfyflowapp with endpoint
  • Loading branch information
xingren23 authored Dec 12, 2023
2 parents 262718f + 126de5a commit a4344f4
Show file tree
Hide file tree
Showing 14 changed files with 660 additions and 366 deletions.
6 changes: 0 additions & 6 deletions .streamlit/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,6 @@ enableStaticServing = false


[client]
# Default: true
caching = true

# Default: true
displayEnabled = true

# Default: true
showErrorDetails = true

Expand Down
9 changes: 4 additions & 5 deletions modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,15 @@ def get_comfy_client():
return comfy_client

@st.cache_resource
def get_inner_comfy_client():
def get_inner_comfy_client(endpoint):
logger.info("get_inner_comfy_client")
from modules.comfyclient import ComfyClient
server_addr = os.getenv('INNER_COMFYUI_SERVER_ADDR')
comfy_client = ComfyClient(server_addr=server_addr)
comfy_client = ComfyClient(server_addr=endpoint)
return comfy_client

def check_inner_comfyui_alive():
def check_inner_comfyui_alive(endpoint):
try:
get_inner_comfy_client().queue_remaining()
get_inner_comfy_client(endpoint).queue_remaining()
return True
except Exception as e:
logger.warning(f"check comfyui alive error, {e}")
Expand Down
13 changes: 8 additions & 5 deletions modules/comfyclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ class ComfyClient:
def __init__(self, server_addr) -> None:
self.client_id = str(uuid.uuid4())
self.server_addr = server_addr
self.timeout = 5
logger.info(f"Comfy client id: {self.client_id}")

def get_node_class(self):
object_info_url = f"{self.server_addr}/object_info"
logger.info(f"Got object info from {object_info_url}")
resp = requests.get(object_info_url, timeout=3)
resp = requests.get(object_info_url)
if resp.status_code != 200:
raise Exception(f"Failed to get object info from {object_info_url}")
return resp.json()
Expand All @@ -33,7 +32,7 @@ def queue_remaining(self):
"""
url = f"{self.server_addr}/prompt"
logger.info(f"Got remaining from {url}")
resp = requests.get(url, timeout=self.timeout)
resp = requests.get(url)
if resp.status_code != 200:
raise Exception(f"Failed to get queue from {url}")
return resp.json()['exec_info']['queue_remaining']
Expand All @@ -42,7 +41,7 @@ def queue_prompt(self, prompt):
p = {"prompt": prompt, "client_id": self.client_id}
data = json.dumps(p).encode('utf-8')
logger.info(f"Sending prompt to server, {self.client_id}")
resp = requests.post(f"{self.server_addr}/prompt", data=data, timeout=self.timeout)
resp = requests.post(f"{self.server_addr}/prompt", data=data)
if resp.status_code != 200:
raise Exception(f"Failed to send prompt to server, {resp.status_code}")
return resp.json()
Expand Down Expand Up @@ -83,7 +82,11 @@ def gen_images(self, prompt, queue):
return prompt_id

def _websocket_loop(self, prompt, queue):
wc_connect = "ws://{}/ws?clientId={}".format(urlparse.urlparse(self.server_addr).netloc, self.client_id)
urlresult = urlparse.urlparse(self.server_addr)
if urlresult.scheme == "http":
wc_connect = "ws://{}/ws?clientId={}".format(urlresult.netloc, self.client_id)
elif urlresult.scheme == "https":
wc_connect = "wss://{}/ws?clientId={}".format(urlresult.netloc, self.client_id)
logger.info(f"Websocket connect url, {wc_connect}")
ws = websocket.WebSocket()
ws.connect(wc_connect)
Expand Down
6 changes: 3 additions & 3 deletions modules/myapp_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class MyAppModel:
def __init__(self) -> None:
self.db_conn = st.experimental_connection('comfyflow_db', type='sql')
self.db_conn = st.connection('comfyflow_db', type='sql')
self.app_talbe_name = 'my_apps'
self._init_table()
logger.debug(f"db_conn: {self.db_conn}, app_talbe_name: {self.app_talbe_name}")
Expand Down Expand Up @@ -85,15 +85,15 @@ def sync_apps(self, apps):
def get_all_apps(self):
with self.session as s:
logger.info("get apps from db")
sql = text(f'SELECT id, name, description, image, app_conf, api_conf, template, url, status FROM {self.app_talbe_name} order by id desc;')
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;')
apps = s.execute(sql).fetchall()
return apps

def get_my_installed_apps(self):
# get installed apps
with self.session as s:
logger.debug("get my apps from db")
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;')
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;')
apps = s.execute(sql, {'status': AppStatus.INSTALLED.value}).fetchall()
return apps

Expand Down
16 changes: 9 additions & 7 deletions modules/new_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ def process_image_edit(api_prompt):
st.session_state['create_prompt'] =api_prompt
inputs, outputs = parse_prompt(api_prompt)
if inputs and outputs:
logger.info(f"edit_prompt_inputs, {inputs}")
st.session_state['edit_prompt_inputs'] = inputs
logger.info(f"create_prompt_inputs, {inputs}")
st.session_state['create_prompt_inputs'] = inputs

logger.info(f"edit_prompt_outputs, {outputs}")
st.session_state['edit_prompt_outputs'] = outputs
logger.info(f"create_prompt_outputs, {outputs}")
st.session_state['create_prompt_outputs'] = outputs

st.success("parse workflow from image successfully")
else:
Expand Down Expand Up @@ -330,8 +330,8 @@ def edit_app_ui(app):

with image_col2:
image_icon = BytesIO(app.image)
input_params = st.session_state.get('edit_prompt_inputs')
output_params = st.session_state.get('edit_prompt_outputs')
input_params = st.session_state.get('create_prompt_inputs')
output_params = st.session_state.get('create_prompt_outputs')
if image_icon and input_params and output_params:
logger.debug(f"input_params: {input_params}, output_params: {output_params}")
_, image_col, _ = st.columns([0.2, 0.6, 0.2])
Expand Down Expand Up @@ -373,6 +373,8 @@ def edit_app_ui(app):
'help': param_help,
}
input_params.append(param)

logger.info(f"params_inputs_options {params_inputs_options}, input_params: {input_params}")

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

st.markdown("Output Params:")
params_outputs = st.session_state.get('edit_prompt_outputs', {})
params_outputs = st.session_state.get('create_prompt_outputs', {})
params_outputs_options = list(params_outputs.keys())

output_params = []
Expand Down
2 changes: 1 addition & 1 deletion modules/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def change_mode_pages(mode):
if mode == "Creator":
pages = ['Home', 'Workspace', "My_Apps"]
elif mode == "Explore":
pages = ['Home', 'App_Store']
pages = ['Home', 'App_Store', 'ComfyUI_Nodes']
else:
pages = [page['page_name'] for _, page in all_pages.items()]
logger.info(f"pages: {pages}, mode: {mode}")
Expand Down
27 changes: 2 additions & 25 deletions modules/preview_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def preview_app_ui(app):
if f"{name}_previewed" in st.session_state:
previewed = st.session_state[f"{name}_previewed"]
if previewed:
st.success(f"Preview app {name} success, back to workspace, you could start or publish the app.")
st.success(f"Preview app {name} success, you could install or publish the app at Workspace page.")
get_workspace_model().update_app_preview(name)
logger.info(f"update preview status for app: {name}")
st.stop()
Expand Down Expand Up @@ -57,27 +57,4 @@ def enter_app_ui(app):
app_data = app.app_conf
comfy_client = get_comfy_client()
comfyflow = Comfyflow(comfy_client=comfy_client, api_data=api_data, app_data=app_data)
comfyflow.create_ui(show_header=False)

def on_back_store():
st.session_state.pop('try_enter_app', None)
logger.info("back to app store")

def try_enter_app_ui(app):
with st.container():
name = app.name
description = app.description
status = app.status
logger.info(f"try app {name}, status: {status}")

with page.stylable_button_container():
header_row = row([0.85, 0.15], vertical_align="top")
header_row.title(f"{name}")
header_row.button("App Store", help="Back to app store", key='try_back_store', on_click=on_back_store)

st.markdown(f"{description}")
api_data = app.api_conf
app_data = app.app_conf
comfy_client = get_inner_comfy_client()
comfyflow = Comfyflow(comfy_client=comfy_client, api_data=api_data, app_data=app_data)
comfyflow.create_ui(show_header=False)
comfyflow.create_ui(show_header=False)
Loading

0 comments on commit a4344f4

Please sign in to comment.