Archived
feat: make CivitAI and ComfyUI server URLs configurable via environment variables
This commit is contained in:
1 parent
bea3ff3120
commit
a886e2d327
4 files changed
+42
-12
No files matched your search
+3
-3
@@ -15,9 +15,9 @@ import folder_paths
|
|||||||
from . import resources
|
from . import resources
|
||||||
from .websocket import broadcast_progress
|
from .websocket import broadcast_progress
|
||||||
|
|
||||||
# Constants
|
# Constants - configurable via environment variables for proxying
|
||||||
CIVITAI_API_BASE = "https://civitai.com/api/v1"
|
CIVITAI_API_BASE = os.environ.get('CIVITAI_API_BASE', "https://civitai.com/api/v1")
|
||||||
CIVITAI_DOWNLOAD_BASE = "https://civitai.com/api/download/models"
|
CIVITAI_DOWNLOAD_BASE = os.environ.get('CIVITAI_DOWNLOAD_BASE', "https://civitai.com/api/download/models")
|
||||||
|
|
||||||
# Model type to ComfyUI folder mapping
|
# Model type to ComfyUI folder mapping
|
||||||
MODEL_TYPE_TO_FOLDER = {
|
MODEL_TYPE_TO_FOLDER = {
|
||||||
|
|||||||
+4
-1
@@ -9,6 +9,9 @@ import requests
|
|||||||
from typing import Dict, List, Optional
|
from typing import Dict, List, Optional
|
||||||
import folder_paths
|
import folder_paths
|
||||||
|
|
||||||
|
# CivitAI API base URL - configurable via environment variable for proxying
|
||||||
|
CIVITAI_API_BASE = os.environ.get('CIVITAI_API_BASE', "https://civitai.com/api/v1")
|
||||||
|
|
||||||
# Resources directory for storing index files
|
# Resources directory for storing index files
|
||||||
RESOURCES_DIR = os.path.join(os.path.dirname(__file__), 'resources')
|
RESOURCES_DIR = os.path.join(os.path.dirname(__file__), 'resources')
|
||||||
os.makedirs(RESOURCES_DIR, exist_ok=True)
|
os.makedirs(RESOURCES_DIR, exist_ok=True)
|
||||||
@@ -55,7 +58,7 @@ def get_civitai_metadata(hash: str) -> Optional[Dict]:
|
|||||||
"""Fetch metadata from CivitAI by hash."""
|
"""Fetch metadata from CivitAI by hash."""
|
||||||
try:
|
try:
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
f"https://civitai.com/api/v1/model-versions/by-hash/{hash}",
|
f"{CIVITAI_API_BASE}/model-versions/by-hash/{hash}",
|
||||||
timeout=5
|
timeout=5
|
||||||
)
|
)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
|
|||||||
+29
-7
@@ -2,9 +2,14 @@
|
|||||||
Basic SDXL Text to Image workflow.
|
Basic SDXL Text to Image workflow.
|
||||||
Schema is defined in basic_sdxl.yaml (auto-generated from WorkflowParams).
|
Schema is defined in basic_sdxl.yaml (auto-generated from WorkflowParams).
|
||||||
"""
|
"""
|
||||||
|
import os
|
||||||
|
import comfy_script.runtime as runtime
|
||||||
from comfy_script.runtime import *
|
from comfy_script.runtime import *
|
||||||
from comfy_script.runtime import _client_id
|
|
||||||
load('http://127.0.0.1:8188/')
|
# ComfyUI server URL - configurable via environment variable
|
||||||
|
COMFYUI_SERVER_URL = os.environ.get('COMFYUI_SERVER_URL', 'http://127.0.0.1:8188/')
|
||||||
|
load(COMFYUI_SERVER_URL)
|
||||||
|
|
||||||
from comfy_script.runtime.nodes import *
|
from comfy_script.runtime.nodes import *
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
@@ -273,22 +278,39 @@ class SDXLWorkflow(BaseWorkflow):
|
|||||||
def run_workflow(**kwargs):
|
def run_workflow(**kwargs):
|
||||||
"""
|
"""
|
||||||
Entry point for the workflow.
|
Entry point for the workflow.
|
||||||
|
|
||||||
Special kwargs (not passed to WorkflowParams):
|
Special kwargs (not passed to WorkflowParams):
|
||||||
save_mode: "disk" | "temporary" | "stream" - how to save output images
|
save_mode: "disk" | "temporary" | "stream" - how to save output images
|
||||||
params_raw: dict - original parameters from frontend (for PNG metadata/recall)
|
params_raw: dict - original parameters from frontend (for PNG metadata/recall)
|
||||||
|
client_id: str - custom client_id for WebSocket events (optional)
|
||||||
"""
|
"""
|
||||||
# Extract special parameters before creating WorkflowParams
|
# Extract special parameters before creating WorkflowParams
|
||||||
save_mode = kwargs.pop('save_mode', 'disk')
|
save_mode = kwargs.pop('save_mode', 'disk')
|
||||||
params_raw = kwargs.pop('params_raw', None)
|
params_raw = kwargs.pop('params_raw', None)
|
||||||
|
custom_client_id = kwargs.pop('client_id', None)
|
||||||
|
|
||||||
required = ['prompt', 'checkpoints', 'seed', 'steps', 'negativePrompt', 'dimensions', 'cfg']
|
required = ['prompt', 'checkpoints', 'seed', 'steps', 'negativePrompt', 'dimensions', 'cfg']
|
||||||
missing = [f for f in required if f not in kwargs]
|
missing = [f for f in required if f not in kwargs]
|
||||||
if missing:
|
if missing:
|
||||||
raise ValueError(f"Missing required fields: {', '.join(missing)}")
|
raise ValueError(f"Missing required fields: {', '.join(missing)}")
|
||||||
|
|
||||||
params = WorkflowParams(**kwargs)
|
params = WorkflowParams(**kwargs)
|
||||||
|
|
||||||
# Create and run workflow with save settings
|
# Create and run workflow with save settings
|
||||||
workflow = SDXLWorkflow(params, params_raw=params_raw, save_mode=save_mode)
|
workflow = SDXLWorkflow(params, params_raw=params_raw, save_mode=save_mode)
|
||||||
return workflow.run()
|
|
||||||
|
# If custom client_id provided, temporarily override comfy_script's client_id
|
||||||
|
original_client_id = getattr(runtime, '_client_id', None)
|
||||||
|
if custom_client_id and original_client_id:
|
||||||
|
runtime._client_id = custom_client_id
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = workflow.run()
|
||||||
|
# Use custom client_id in response if provided
|
||||||
|
if custom_client_id:
|
||||||
|
result['client_id'] = custom_client_id
|
||||||
|
return result
|
||||||
|
finally:
|
||||||
|
# Restore original client_id
|
||||||
|
if custom_client_id and original_client_id:
|
||||||
|
runtime._client_id = original_client_id
|
||||||
@@ -1,5 +1,10 @@
|
|||||||
|
import os
|
||||||
from comfy_script.runtime import *
|
from comfy_script.runtime import *
|
||||||
load()
|
|
||||||
|
# ComfyUI server URL - configurable via environment variable
|
||||||
|
COMFYUI_SERVER_URL = os.environ.get('COMFYUI_SERVER_URL', 'http://127.0.0.1:8188/')
|
||||||
|
load(COMFYUI_SERVER_URL)
|
||||||
|
|
||||||
from comfy_script.runtime.nodes import *
|
from comfy_script.runtime.nodes import *
|
||||||
|
|
||||||
def f(wf):
|
def f(wf):
|
||||||
|
|||||||
Reference in new issue
Block a user