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
+38
-8
No files matched your search
+3
-3
@@ -15,9 +15,9 @@ import folder_paths
|
||||
from . import resources
|
||||
from .websocket import broadcast_progress
|
||||
|
||||
# Constants
|
||||
CIVITAI_API_BASE = "https://civitai.com/api/v1"
|
||||
CIVITAI_DOWNLOAD_BASE = "https://civitai.com/api/download/models"
|
||||
# Constants - configurable via environment variables for proxying
|
||||
CIVITAI_API_BASE = os.environ.get('CIVITAI_API_BASE', "https://civitai.com/api/v1")
|
||||
CIVITAI_DOWNLOAD_BASE = os.environ.get('CIVITAI_DOWNLOAD_BASE', "https://civitai.com/api/download/models")
|
||||
|
||||
# Model type to ComfyUI folder mapping
|
||||
MODEL_TYPE_TO_FOLDER = {
|
||||
|
||||
+4
-1
@@ -9,6 +9,9 @@ import requests
|
||||
from typing import Dict, List, Optional
|
||||
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_DIR = os.path.join(os.path.dirname(__file__), 'resources')
|
||||
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."""
|
||||
try:
|
||||
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
|
||||
)
|
||||
if response.status_code == 200:
|
||||
|
||||
+25
-3
@@ -2,9 +2,14 @@
|
||||
Basic SDXL Text to Image workflow.
|
||||
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 _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 pydantic import BaseModel, Field
|
||||
@@ -277,10 +282,12 @@ def run_workflow(**kwargs):
|
||||
Special kwargs (not passed to WorkflowParams):
|
||||
save_mode: "disk" | "temporary" | "stream" - how to save output images
|
||||
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
|
||||
save_mode = kwargs.pop('save_mode', 'disk')
|
||||
params_raw = kwargs.pop('params_raw', None)
|
||||
custom_client_id = kwargs.pop('client_id', None)
|
||||
|
||||
required = ['prompt', 'checkpoints', 'seed', 'steps', 'negativePrompt', 'dimensions', 'cfg']
|
||||
missing = [f for f in required if f not in kwargs]
|
||||
@@ -291,4 +298,19 @@ def run_workflow(**kwargs):
|
||||
|
||||
# Create and run workflow with save settings
|
||||
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 *
|
||||
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 *
|
||||
|
||||
def f(wf):
|
||||
|
||||
Reference in new issue
Block a user