#!/bin/bash # Using 127.0.0.1 for internal process communication ARGS="--listen 127.0.0.1 --port 8188 --cpu" # This checks if USE_PERSISTENT_DATA is enabled and the /data directory exists case "$USE_PERSISTENT_DATA" in true|1|yes) if [ -d "/data" ]; then echo "Directory /data detected. Enabling output persistence." ARGS="$ARGS --output-directory /data/" fi ;; esac # Start ComfyUI in the background echo "Starting ComfyUI with arguments: $ARGS" python main.py $ARGS & # Wait for ComfyUI to be ready (Port 8188) # This prevents the "Connection Refused" error in your app.py echo "Waiting for ComfyUI to respond on port 8188..." while ! nc -z 127.0.0.1 8188; do sleep 2 done echo "ComfyUI engine is ready." # Start the main application (Gradio/UI) # Hugging Face requires this app to listen on the port specified in the $PORT variable. # 'exec' ensures the app receives termination signals properly. echo "Starting app.py on port ${PORT:-7860}..." exec python app.py --port ${PORT:-7860}