Skip to content

Commit

Permalink
Merge pull request #7 from ComfyWorkflows/testing-pipeline
Browse files Browse the repository at this point in the history
better support for automatically handling missing models
  • Loading branch information
thecooltechguy authored Mar 7, 2024
2 parents ac201ae + 7313ce7 commit bac9a88
Show file tree
Hide file tree
Showing 43 changed files with 26,455 additions and 342 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ show-in-file-manager==1.1.4
tqdm==4.66.2
urllib3==2.2.0
Werkzeug==3.0.1
websocket-client==1.7.0
selenium==4.18.1
Binary file modified server/.DS_Store
Binary file not shown.
Binary file added server/example.mp4
Binary file not shown.
Binary file added server/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 40 additions & 3 deletions server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from flask import Flask, jsonify, request, render_template
from showinfm import show_in_file_manager
from settings import PROJECTS_DIR, MODELS_DIR, TEMPLATES_DIR
import requests
import os, psutil, sys
from utils import (
CONFIG_FILEPATH,
Expand All @@ -23,8 +24,11 @@
set_launcher_state_data,
slugify,
update_config,
check_url_structure
)

CW_ENDPOINT = os.environ.get("CW_ENDPOINT", "http://bore.pub:24819/")

app = Flask(
__name__, static_url_path="", static_folder="../web/dist", template_folder="../web/dist"
)
Expand Down Expand Up @@ -120,7 +124,12 @@ def create_project():
if os.path.exists(template_workflow_json_fp):
with open(template_workflow_json_fp, "r") as f:
template_workflow_json = json.load(f)
launcher_json = get_launcher_json_for_workflow_json(template_workflow_json)
res = get_launcher_json_for_workflow_json(template_workflow_json)
if (res["success"] and res["launcher_json"]):
launcher_json = res["launcher_json"]
else:
return jsonify({ "success": False, "missing_models": [], "error": res["error"] })

create_comfyui_project(
project_path, models_path, id=id, name=name, launcher_json=launcher_json
)
Expand All @@ -132,6 +141,9 @@ def import_project():
request_data = request.get_json()
name = request_data["name"]
import_json = request_data["import_json"]
resolved_missing_models = request_data["resolved_missing_models"]
skipping_model_validation = request_data["skipping_model_validation"]
# skipping_model_validation = request_data.get("skipping_model_validation")

# set id to a folder friendly name of the project name (lowercase, no spaces, etc.)
id = slugify(name)
Expand All @@ -146,11 +158,36 @@ def import_project():
launcher_json = import_json
else:
print("Detected workflow json format, converting to launcher json format")
launcher_json = get_launcher_json_for_workflow_json(import_json)
#only resolve missing models for workflows w/ workflow json format
skip_model_validation = True if skipping_model_validation else False
print(f"import_project value of skip_model_validation: {skip_model_validation}")
if len(resolved_missing_models) > 0:
print(f"import_project entering for loop for resolved_missing_models: {resolved_missing_models}")
for model in resolved_missing_models:
if (model["filename"] is None or model["node_type"] is None or model["dest_relative_path"] is None):
return jsonify({ "success": False, "error": f"one of the resolved models has an empty filename, node type, or destination path. please try again." })
elif (model["source"]["url"] is not None and model["source"]["file_id"] is None):
is_valid = check_url_structure(model["source"]["url"])
if (is_valid is False):
return jsonify({ "success": False, "error": f"the url f{model['source']['url']} is invalid. please make sure it is a link to a model file on huggingface or a civitai model." })
elif (model["source"]["file_id"] is None and model["source"]["url"] is None):
return jsonify({ "success": False, "error": f"you didn't select one of the suggestions (or import a url) for the following missing file: {model['filename']}" })
skip_model_validation = True
# print(f"value of import_json: {import_json}")
print(f"value of resolved_missing_models: {resolved_missing_models}")
print(f"value of skip_model_validation: {skip_model_validation}")
res = get_launcher_json_for_workflow_json(import_json, resolved_missing_models, skip_model_validation)
if (res["success"] and res["launcher_json"]):
launcher_json = res["launcher_json"]
elif (res["success"] is False and res["error"] == "MISSING_MODELS" and len(res["missing_models"]) > 0):
return jsonify({ "success": False, "missing_models": res["missing_models"], "error": res["error"] })
else:
print(f"something went wrong when fetching res from get_launcher_json_for_workflow_json: {res}")
return
create_comfyui_project(
project_path, models_path, id=id, name=name, launcher_json=launcher_json
)
return jsonify({"success": True, "id": id})
return jsonify({"success": True, "id": id})


@app.route("/api/projects/<id>/start", methods=["POST"])
Expand Down
Loading

0 comments on commit bac9a88

Please sign in to comment.