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

Commit

Permalink
fix: export error, is_actived error
Browse files Browse the repository at this point in the history
fix: publish with workflow_conf
fix: config.toml
  • Loading branch information
xingren23 committed Dec 12, 2023
1 parent f3ca74b commit 126de5a
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 40 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
53 changes: 31 additions & 22 deletions modules/publish_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ def get_model_meta(model_url):
def get_endpoint_object_info(endpoint):
ret = requests.get(f"{endpoint}/object_info")
if ret.status_code != 200:
raise Exception(f"Failed to get comfyflow object info, {ret.content}")
ret_json = ret.json()
return ret_json
logger.error(f"Failed to get comfyflow object info, {ret.content}")
return None
else:
return ret.json()


def get_node_endpoint(session_cookie):
Expand All @@ -82,7 +83,7 @@ def get_node_endpoint(session_cookie):
else:
return None

def do_publish_app(name, description, image, app_conf, api_conf, endpoint, template, status, cookies=None):
def do_publish_app(name, description, image, app_conf, api_conf, workflow_conf, endpoint, template, status, cookies=None):
comfyflow_api = os.getenv('COMFYFLOW_API_URL')
# post app to comfyflow.app
app = {
Expand All @@ -91,23 +92,31 @@ def do_publish_app(name, description, image, app_conf, api_conf, endpoint, templ
"image": image,
"app_conf": app_conf,
"api_conf": api_conf,
"workflow_conf": workflow_conf,
"endpoint": endpoint,
"template": template,
"status": status
}
logger.debug(f"publish app to comfyflow.app, {app}")
logger.info(f"publish app to comfyflow.app, {app}")
ret = requests.post(f"{comfyflow_api}/api/app/publish", json=app, cookies=cookies)
if ret.status_code != 200:
logger.error(f"publish app failed, {name} {ret.content}")
return None
st.error(f"publish app failed, {name} {ret.content}")
return ret
else:
logger.info(f"publish app success, {name}")
st.success(f"publish app success, {name}")
return ret

def on_publish_workspace():
st.session_state.pop('publish_app', None)
logger.info("back to workspace")

def is_comfyui_model_path(model_path):
for ext in comfyui_supported_pt_extensions:
if isinstance(model_path, str) and model_path.endswith(ext):
return True
return False

def publish_app_ui(app, cookies):
logger.info("Loading publish page")
Expand All @@ -134,7 +143,7 @@ def publish_app_ui(app, cookies):
# get endpoint object info
endpoint_object_info = get_endpoint_object_info(endpoint)
if not endpoint_object_info:
st.error(f"Failed to get comfyflow object info, {endpoint}")
st.error(f"Failed to get comfyui {endpoint} object info, please check comfyui node.")
st.stop()
else:
# parse app nodes
Expand All @@ -153,16 +162,20 @@ def publish_app_ui(app, cookies):
with st.expander("Parse comfyui node info", expanded=True):
for node_id in api_data_json:
inputs = api_data_json[node_id]['inputs']
class_type = api_data_json[node_id]['class_type']
# check model path
for key, value in inputs.items():
if isinstance(value, str) and value.find('.') != -1:
model_type = value.split('.')[-1]
logger.info(f"model_type, {model_type}")
if f'.{model_type}' not in comfyui_supported_pt_extensions:
st.write(f":red[Invalid model path\, {value}]")
st.session_state['publish_invalid_node'] = True
else:
st.write(f":green[Check model path\, {value}]")
try:
if is_comfyui_model_path(value):
model_options = endpoint_object_info[class_type]['input']['required'][key][0]
if value not in model_options:
st.write(f":red[Invalid model path\, {value}]")
st.session_state['publish_invalid_node'] = True
else:
st.write(f":green[Check model path\, {value}]")
except Exception as e:
st.write(f":red[Invalid model path\, {value}]")
st.session_state['publish_invalid_node'] = True

# # config app models
# with st.expander("Config app models", expanded=True):
Expand All @@ -186,7 +199,7 @@ def publish_app_ui(app, cookies):
publish_button = st.button("Publish", key='publish_button', type='primary',
help="Publish app to store and share with your friends")
if publish_button:
if 'publish_invalid_node' in st.session_state:
if st.session_state.get('publish_invalid_node', False):
st.warning("Invalid node, please check node info.")
else:
# # check model url
Expand Down Expand Up @@ -228,10 +241,6 @@ def publish_app_ui(app, cookies):

# convert image to base64
image_base64 = base64.b64encode(app.image).decode('utf-8')

# call api to publish app
ret = do_publish_app(app.name, app.description, image_base64, app.app_conf, app.api_conf, endpoint, app.template, AppStatus.PUBLISHED.value, cookies)
if ret:
st.success("Publish success, you can share this app with your friends.")
else:
st.error("Publish app error")
do_publish_app(app.name, app.description, image_base64, app.app_conf, app.api_conf, app.workflow_conf, endpoint, app.template, AppStatus.PUBLISHED.value, cookies)
21 changes: 14 additions & 7 deletions pages/2_💡_App Store.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,11 @@ def click_enter_app(app):
st.session_state["try_enter_app"] = app_details

def is_actived(app):
active_nodes = st.session_state['active_endpoints']
endpoint = app.get('endpoint', '')
if endpoint in active_nodes:
return True
if 'active_endpoints' in st.session_state:
active_nodes = st.session_state['active_endpoints']
endpoint = app.get('endpoint', '')
if endpoint in active_nodes:
return True
return False

def create_app_info_ui(app):
Expand Down Expand Up @@ -291,13 +292,19 @@ def try_enter_app_ui(app):
comfyflow_token = get_comfyflow_token()
if comfyflow_token is not None:
cookies = {'comfyflow_token': comfyflow_token}
active_nodes = get_active_nodes(cookies)
active_endpoints = [node['endpoint'] for node in active_nodes]
st.session_state['active_endpoints'] = active_endpoints
st.session_state['token_cookie'] = cookies
else:
cookies = None
else:
cookies = st.session_state['token_cookie']

if cookies is None:
st.error("Please login first at home page :point_left:")
st.stop()

active_nodes = get_active_nodes(cookies)
active_endpoints = [node['endpoint'] for node in active_nodes]
st.session_state['active_endpoints'] = active_endpoints

if 'try_enter_app' in st.session_state:
app = st.session_state['try_enter_app']
Expand Down
8 changes: 5 additions & 3 deletions pages/3_📚_Workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,11 @@ def create_operation_ui(app):
if app_preview_ret == AppStatus.ERROR.value:
st.error(f"Edit app {name} failed, please check the log")


operate_row.download_button("💾 Export", data=app.workflow_conf, file_name=f"{app.name}_workflow.json", help="Export workflow to json", key=f"{id}-button-export",
disabled=disabled)
if 'workflow_conf' in app:
operate_row.download_button("💾 Export", data=app.workflow_conf, file_name=f"{app.name}_workflow.json", help="Export workflow to json", key=f"{id}-button-export",
disabled=disabled)
else:
operate_row.button("💾 Export", help="Export workflow to json", key=f"{id}-button-export", disabled=True)

install_button = operate_row.button("📲 Install", help="Install the app", key=f"{id}-button-install",
on_click=click_install_app, args=(app,), disabled=disabled)
Expand Down
4 changes: 2 additions & 2 deletions pages/4_💻_ComfyUI_Nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def submit_del_key(session_cookie, idx, key_id):
logger.error(f"New key created failed, {req.json()}")

def submit_new_node(session_cookie):
logger.debug(f"click new node")
logger.debug("click new node")
node_name = st.session_state["new_node_name"]
node_description = st.session_state["new_node_description"]
node_endpoint = st.session_state["new_node_endpoint"]
Expand All @@ -68,7 +68,7 @@ def submit_new_node(session_cookie):
logger.error(f"New node created failed, {req.json()}")

def submit_active_node(session_cookie):
logger.debug(f"click active node")
logger.debug("click active node")
invite_key = st.session_state["invite_node_key"]
api_url = f'{os.environ.get("COMFYFLOW_API_URL")}/api/node/key/active'
req = requests.post(api_url, cookies=session_cookie, json={"value": invite_key})
Expand Down

0 comments on commit 126de5a

Please sign in to comment.