File size: 2,473 Bytes
86d4cbe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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"]