from .nodes.InputString import FramerComfyInputStringNode from .nodes.InputNumber import FramerComfyInputNumberNode from .nodes.InputImage import FramerComfyInputImageNode from .nodes.InputFloat import FramerComfyFloatInputNode from .nodes.InputBoolean import FramerComfyBooleanInputNode from .nodes.OutputImage import FramerComfySaveImageNode NODE_CLASS_MAPPINGS = { "FramerComfyInputStringNode": FramerComfyInputStringNode, "FramerComfyInputNumberNode": FramerComfyInputNumberNode, "FramerComfyInputImageNode": FramerComfyInputImageNode, "FramerComfyFloatInputNode": FramerComfyFloatInputNode, "FramerComfyBooleanInputNode": FramerComfyBooleanInputNode, "FramerComfySaveImageNode": FramerComfySaveImageNode } NODE_DISPLAY_NAME_MAPPINGS = { "FramerComfyInputStringNode": "FramerComfy Input String", "FramerComfyInputNumberNode": "FramerComfy Input Number", "FramerComfyInputImageNode": "FramerComfy Input Image", "FramerComfyFloatInputNode": "FramerComfy Input Float", "FramerComfyBooleanInputNode": "FramerComfy Input Boolean", "FramerComfySaveImageNode": "FramerComfy Save Image" } import sys import os import random import traceback from aiohttp import web from io import StringIO from .hf import deploy_workflow from .generate_reqs import generate_requirements ext_dir = os.path.dirname(__file__) sys.path.append(ext_dir) try: import black except ImportError: print("Unable to import requirements for ComfyUI-SaveAsScript.") print("Installing...") import importlib spec = importlib.util.spec_from_file_location( "impact_install", os.path.join(os.path.dirname(__file__), "install.py") ) impact_install = importlib.util.module_from_spec(spec) spec.loader.exec_module(impact_install) print("Successfully installed. Hopefully, at least.") # Prevent reimporting of custom nodes os.environ["RUNNING_IN_COMFYUI"] = "TRUE" from comfyui_to_python import ComfyUItoPython sys.path.append(os.path.dirname(os.path.dirname(ext_dir))) import server WEB_DIRECTORY = "js" @server.PromptServer.instance.routes.post("/saveasscript") async def save_as_script(request): try: data = await request.json() name = data["name"] workflow = data["workflow"] workflow_models = data["workflow_models"] hf_access_token = data["hf_access_token"] sio = StringIO() app_code_generator = ComfyUItoPython(workflow=workflow, output_file=sio, workflow_models=workflow_models) app_code = app_code_generator.execute() name = f'FramerComfy_{name}_{str(random.randint(1000000000, 9999999999))}' requirements_file = generate_requirements() print("Deploying to Hugging Face...") # Deploy to Hugging Face deploy_workflow(name, app_code, requirements_file, hf_access_token) sio.seek(0) data = sio.read() return web.Response(text=data, status=200) except Exception as e: traceback.print_exc() return web.Response(text=str(e), status=500)