mohamedsobhi777's picture
Synced repo using 'sync_with_huggingface' Github Action
86d4cbe verified
import os
import json
import folder_paths
import server
from aiohttp import web
import traceback
from comfyui_to_python import ComfyUItoPython
# Add API routes for FramerComfy
@server.PromptServer.instance.routes.post("/framercomfy/deploy")
async def deploy_to_framercomfy(request):
try:
data = await request.json()
workflow_json = data.get("workflow", {})
models = data.get("models", [])
# Process workflow for deployment
result = process_workflow(workflow_json, models)
return web.json_response(result)
except Exception as e:
traceback.print_exc()
return web.json_response({"error": str(e)}, status=500)
def process_workflow(workflow_json, models):
# Directory setup for output
output_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), "output")
os.makedirs(output_dir, exist_ok=True)
output_file = os.path.join(output_dir, "framercomfy_workflow.py")
# Use the existing ComfyUItoPython to generate the code
converter = ComfyUItoPython(
workflow=json.dumps(workflow_json),
workflow_models=models,
output_file=output_file,
queue_size=1,
needs_init_custom_nodes=True
)
generated_code = converter.execute()
# Here you would add whatever else needs to happen for deployment
return {
"success": True,
"message": "Workflow deployed successfully!",
"output_file": output_file
}
# Set up web directory for static files
web_directory = os.path.join(os.path.dirname(os.path.abspath(__file__)), "web")
# Register our web directory for static files
folder_paths.folder_names_and_paths["framercomfy_web"] = ([web_directory], folder_paths.PRIORITY_EXTENSION)
# Add JS requirements
comfy_ui_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
javascript_path = os.path.join(comfy_ui_path, "web", "extensions")
def load_javascript_extensions():
# Create a list of JavaScript extensions to load
extensions = [
os.path.join("framercomfy_web", "framer_comfy_dialog.js"),
os.path.join("framercomfy_web", "framer_comfy_api.js"),
]
# Register with ComfyUI
return extensions
# Register our JavaScript extensions
NODE_CLASS_MAPPINGS = {}
NODE_DISPLAY_NAME_MAPPINGS = {}
WEB_DIRECTORY = web_directory
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]