forked from ace-step/ACE-Step-1.5
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstart_gradio_ui_manual.sh
More file actions
executable file
·473 lines (421 loc) · 15.3 KB
/
start_gradio_ui_manual.sh
File metadata and controls
executable file
·473 lines (421 loc) · 15.3 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
#!/usr/bin/env bash
# ACE-Step Gradio Web UI Launcher - Linux (CUDA)
# This script launches the Gradio web interface for ACE-Step
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# ==================== Load .env Configuration ====================
# Load settings from .env file if it exists
_load_env_file() {
local env_file="${SCRIPT_DIR}/.env"
if [[ ! -f "$env_file" ]]; then
return 0
fi
echo "[Config] Loading configuration from .env file..."
# Read .env file and export variables
while IFS='=' read -r key value || [[ -n "$key" ]]; do
# Skip empty lines and comments
[[ -z "$key" || "$key" =~ ^[[:space:]]*# ]] && continue
# Trim whitespace from key and value
key="${key#"${key%%[![:space:]]*}"}"
key="${key%"${key##*[![:space:]]}"}"
value="${value#"${value%%[![:space:]]*}"}"
value="${value%"${value##*[![:space:]]}"}"
# Map .env variable names to script variables
case "$key" in
ACESTEP_CONFIG_PATH)
[[ -n "$value" ]] && CONFIG_PATH="--config_path $value"
;;
ACESTEP_LM_MODEL_PATH)
[[ -n "$value" ]] && LM_MODEL_PATH="--lm_model_path $value"
;;
ACESTEP_INIT_LLM)
if [[ -n "$value" && "$value" != "auto" ]]; then
INIT_LLM="--init_llm $value"
fi
;;
ACESTEP_DOWNLOAD_SOURCE)
if [[ -n "$value" && "$value" != "auto" ]]; then
DOWNLOAD_SOURCE="--download-source $value"
fi
;;
ACESTEP_API_KEY)
[[ -n "$value" ]] && API_KEY="--api-key $value"
;;
PORT)
[[ -n "$value" ]] && PORT="$value"
;;
SERVER_NAME)
[[ -n "$value" ]] && SERVER_NAME="$value"
;;
LANGUAGE)
[[ -n "$value" ]] && LANGUAGE="$value"
;;
ACESTEP_BATCH_SIZE)
[[ -n "$value" ]] && BATCH_SIZE="--batch_size $value"
;;
esac
done < "$env_file"
echo "[Config] Configuration loaded from .env"
}
_load_env_file
# ==================== Manual Startup Configuration ====================
# Ask for manual settings
_load_manual() {
echo -e "\033[1;36m"
echo "======================================================"
echo " ACE-Step Manual Launch Mode"
echo "======================================================"
echo
while true; do
read -rp "Continue with manual configuration? (Y/N): " MANUAL_CHOICE
case "$MANUAL_CHOICE" in
[Yy])
break ;;
[Nn])
echo -e "\033[0m"
echo "Proceeding with automatic configuration..."
echo
return 0 ;;
*)
echo "Invalid input. Please enter Y or N." ;;
esac
done
echo
echo "-------------------- Update Settings --------------------"
while true; do
read -rp "Check for updates before launch? (Y/N): " UPDATE_CHOICE
case "$UPDATE_CHOICE" in
[Yy])
CHECK_UPDATE="true"
break ;;
[Nn])
CHECK_UPDATE="false"
break ;;
*)
echo "Invalid input. Please enter Y or N." ;;
esac
done
echo
echo "-------------------- Select DiT Model --------------------"
echo "1) acestep-v15-base"
echo "2) acestep-v15-sft"
echo "3) acestep-v15-turbo (Recommended)"
echo "4) acestep-v15-turbo-rl"
echo
while true; do
read -rp "Enter selection (1-4): " DIT_CHOICE
case "$DIT_CHOICE" in
1)
CONFIG_PATH="--config_path acestep-v15-base"
break ;;
2)
CONFIG_PATH="--config_path acestep-v15-sft"
break ;;
3)
CONFIG_PATH="--config_path acestep-v15-turbo"
break ;;
4)
CONFIG_PATH="--config_path acestep-v15-turbo-rl"
break ;;
*)
echo "Invalid input. Please enter a number between 1 and 4." ;;
esac
done
echo
echo "-------------------- Select LM Model --------------------"
echo "1) acestep-5Hz-lm-0.6B (Recommended)"
echo "2) acestep-5Hz-lm-1.7B"
echo "3) acestep-5Hz-lm-4B"
echo "4) Launch without LM Model"
echo
while true; do
read -rp "Enter selection (1-4): " LM_CHOICE
case "$LM_CHOICE" in
1)
LM_MODEL_PATH="--lm_model_path acestep-5Hz-lm-0.6B"
INIT_LLM="--init_llm true"
break ;;
2)
LM_MODEL_PATH="--lm_model_path acestep-5Hz-lm-1.7B"
INIT_LLM="--init_llm true"
break ;;
3)
LM_MODEL_PATH="--lm_model_path acestep-5Hz-lm-4B"
INIT_LLM="--init_llm true"
break ;;
4)
LM_MODEL_PATH=""
INIT_LLM="--init_llm false"
break ;;
*)
echo "Invalid input. Please enter a number between 1 and 4." ;;
esac
done
echo
echo "-------------------- CPU Offload Option --------------------"
while true; do
read -rp "Enable CPU Offload? (Y/N): " OFFLOAD_CHOICE
case "$OFFLOAD_CHOICE" in
[Yy])
OFFLOAD_TO_CPU="--offload_to_cpu true"
break ;;
[Nn])
OFFLOAD_TO_CPU="--offload_to_cpu false"
break ;;
*)
echo "Invalid input. Please enter Y or N." ;;
esac
done
echo -e "\033[0m"
echo "Manual configuration applied successfully."
echo
}
_load_manual
# ==================== Configuration ====================
# Default values (used if not set in .env file)
# You can override these by uncommenting and modifying the lines below
# or by creating a .env file (recommended to survive updates)
# Server settings
: "${PORT:=7860}"
: "${SERVER_NAME:=127.0.0.1}"
# SERVER_NAME="0.0.0.0"
SHARE="${SHARE:-}"
# SHARE="--share"
# Reset LANGUAGE if it contains an invalid value (e.g. system locale like en_CA:en)
case "$LANGUAGE" in
en|zh|he|ja) ;;
*) unset LANGUAGE ;;
esac
# UI language: en, zh, he, ja
: "${LANGUAGE:=en}"
# Batch size: default batch size for generation (1 to GPU-dependent max)
# When not specified, defaults to min(2, GPU_max)
BATCH_SIZE="${BATCH_SIZE:-}"
# BATCH_SIZE="--batch_size 4"
# Model settings
: "${CONFIG_PATH:=--config_path acestep-v15-turbo}"
: "${LM_MODEL_PATH:=--lm_model_path acestep-5Hz-lm-0.6B}"
# OFFLOAD_TO_CPU="--offload_to_cpu true"
OFFLOAD_TO_CPU="${OFFLOAD_TO_CPU:-}"
# LLM (Language Model) initialization settings
# By default, LLM is auto-enabled/disabled based on GPU VRAM:
# - <=6GB VRAM: LLM disabled (DiT-only mode)
# - >6GB VRAM: LLM enabled
# Values: auto (default), true (force enable), false (force disable)
INIT_LLM="${INIT_LLM:-}"
# INIT_LLM="--init_llm auto"
# INIT_LLM="--init_llm true"
# INIT_LLM="--init_llm false"
# Download source settings
# Preferred download source: auto (default), huggingface, or modelscope
DOWNLOAD_SOURCE="${DOWNLOAD_SOURCE:-}"
# DOWNLOAD_SOURCE="--download-source modelscope"
# DOWNLOAD_SOURCE="--download-source huggingface"
# Update check on startup (set to "false" to disable)
: "${CHECK_UPDATE:=true}"
# CHECK_UPDATE="false"
# Auto-initialize models on startup
: "${INIT_SERVICE:=--init_service true}"
# API settings (enable REST API alongside Gradio)
ENABLE_API="${ENABLE_API:-}"
# ENABLE_API="--enable-api"
API_KEY="${API_KEY:-}"
# API_KEY="--api-key sk-your-secret-key"
# Authentication settings
AUTH_USERNAME="${AUTH_USERNAME:-}"
# AUTH_USERNAME="--auth-username admin"
AUTH_PASSWORD="${AUTH_PASSWORD:-}"
# AUTH_PASSWORD="--auth-password password"
# ==================== Launch ====================
# ==================== Startup Update Check ====================
_startup_update_check() {
[[ "$CHECK_UPDATE" != "true" ]] && return 0
command -v git &>/dev/null || return 0
cd "$SCRIPT_DIR" || return 0
git rev-parse --git-dir &>/dev/null 2>&1 || return 0
local branch commit remote_commit
branch="$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "main")"
commit="$(git rev-parse --short HEAD 2>/dev/null || echo "")"
[[ -z "$commit" ]] && return 0
echo "[Update] Checking for updates..."
# Fetch with timeout (10s)
local fetch_ok=0
if command -v timeout &>/dev/null; then
timeout 10 git fetch origin --quiet 2>/dev/null && fetch_ok=1
elif command -v gtimeout &>/dev/null; then
gtimeout 10 git fetch origin --quiet 2>/dev/null && fetch_ok=1
else
git fetch origin --quiet 2>/dev/null && fetch_ok=1
fi
if [[ $fetch_ok -eq 0 ]]; then
echo "[Update] Network unreachable, skipping."
echo
return 0
fi
remote_commit="$(git rev-parse --short "origin/$branch" 2>/dev/null || echo "")"
if [[ -z "$remote_commit" || "$commit" == "$remote_commit" ]]; then
echo "[Update] Already up to date ($commit)."
echo
return 0
fi
echo
echo "========================================"
echo " Update available!"
echo "========================================"
echo " Current: $commit -> Latest: $remote_commit"
echo
echo " Recent changes:"
git --no-pager log --oneline "HEAD..origin/$branch" 2>/dev/null | head -10
echo
read -rp "Update now before starting? (Y/N): " update_choice
if [[ "${update_choice^^}" == "Y" ]]; then
if [[ -f "$SCRIPT_DIR/check_update.sh" ]]; then
bash "$SCRIPT_DIR/check_update.sh"
else
echo "Pulling latest changes..."
git pull --ff-only origin "$branch" 2>/dev/null || {
echo "[Update] Update failed. Please run: git pull"
}
fi
else
echo "[Update] Skipped. Run ./check_update.sh to update later."
fi
echo
}
_startup_update_check
echo "Starting ACE-Step Gradio Web UI..."
echo "Server will be available at: http://${SERVER_NAME}:${PORT}"
echo
# ==================== Standard uv Workflow ====================
# Works on all platforms: x86_64 Linux (cu128), aarch64 Linux/DGX Spark (cu130),
# macOS (MPS), Windows (cu128). uv resolves the correct PyTorch wheels via
# platform-specific index mappings in pyproject.toml.
# Check if uv is installed
if ! command -v uv &>/dev/null; then
# Try common install locations
if [[ -x "$HOME/.local/bin/uv" ]]; then
export PATH="$HOME/.local/bin:$PATH"
elif [[ -x "$HOME/.cargo/bin/uv" ]]; then
export PATH="$HOME/.cargo/bin:$PATH"
fi
fi
if ! command -v uv &>/dev/null; then
echo
echo "========================================"
echo "uv package manager not found!"
echo "========================================"
echo
echo "ACE-Step requires the uv package manager."
echo
read -rp "Install uv now? (Y/N): " INSTALL_UV
if [[ "${INSTALL_UV^^}" == "Y" ]]; then
echo
bash "$SCRIPT_DIR/install_uv.sh" --silent
INSTALL_RESULT=$?
if [[ $INSTALL_RESULT -eq 0 ]]; then
echo
echo "========================================"
echo "uv installed successfully!"
echo "========================================"
echo
export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$PATH"
if command -v uv &>/dev/null; then
echo "uv is now available!"
uv --version
echo
else
echo
echo "uv installed but not in PATH yet."
echo "Please restart your terminal or run:"
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
echo
exit 1
fi
else
echo
echo "========================================"
echo "Installation failed!"
echo "========================================"
echo
echo "Please install uv manually:"
echo " curl -LsSf https://astral.sh/uv/install.sh | sh"
echo
exit 1
fi
else
echo
echo "Installation cancelled."
echo
echo "To use ACE-Step, please install uv:"
echo " curl -LsSf https://astral.sh/uv/install.sh | sh"
echo
exit 1
fi
fi
echo "[Environment] Using uv package manager..."
echo
# Check if virtual environment exists
if [[ ! -d "$SCRIPT_DIR/.venv" ]]; then
echo "[Setup] Virtual environment not found. Setting up environment..."
echo "This will take a few minutes on first run."
echo
echo "Running: uv sync"
echo
if ! (cd "$SCRIPT_DIR" && uv sync); then
echo
echo "[Retry] Online sync failed, retrying in offline mode..."
echo
if ! (cd "$SCRIPT_DIR" && uv sync --offline); then
echo
echo "========================================"
echo "[Error] Failed to setup environment"
echo "========================================"
echo
echo "Both online and offline modes failed."
echo "Please check:"
echo " 1. Your internet connection (required for first-time setup)"
echo " 2. Ensure you have enough disk space"
echo " 3. Try running: uv sync manually"
exit 1
fi
fi
echo
echo "========================================"
echo "Environment setup completed!"
echo "========================================"
echo
fi
echo "Starting ACE-Step Gradio UI..."
echo
# Build command with optional parameters
ACESTEP_ARGS="acestep --port $PORT --server-name $SERVER_NAME --language $LANGUAGE"
[[ -n "$SHARE" ]] && ACESTEP_ARGS="$ACESTEP_ARGS $SHARE"
[[ -n "$CONFIG_PATH" ]] && ACESTEP_ARGS="$ACESTEP_ARGS $CONFIG_PATH"
[[ -n "$LM_MODEL_PATH" ]] && ACESTEP_ARGS="$ACESTEP_ARGS $LM_MODEL_PATH"
[[ -n "$OFFLOAD_TO_CPU" ]] && ACESTEP_ARGS="$ACESTEP_ARGS $OFFLOAD_TO_CPU"
[[ -n "$INIT_LLM" ]] && ACESTEP_ARGS="$ACESTEP_ARGS $INIT_LLM"
[[ -n "$DOWNLOAD_SOURCE" ]] && ACESTEP_ARGS="$ACESTEP_ARGS $DOWNLOAD_SOURCE"
[[ -n "$INIT_SERVICE" ]] && ACESTEP_ARGS="$ACESTEP_ARGS $INIT_SERVICE"
[[ -n "$BATCH_SIZE" ]] && ACESTEP_ARGS="$ACESTEP_ARGS $BATCH_SIZE"
[[ -n "$ENABLE_API" ]] && ACESTEP_ARGS="$ACESTEP_ARGS $ENABLE_API"
[[ -n "$API_KEY" ]] && ACESTEP_ARGS="$ACESTEP_ARGS $API_KEY"
[[ -n "$AUTH_USERNAME" ]] && ACESTEP_ARGS="$ACESTEP_ARGS $AUTH_USERNAME"
[[ -n "$AUTH_PASSWORD" ]] && ACESTEP_ARGS="$ACESTEP_ARGS $AUTH_PASSWORD"
cd "$SCRIPT_DIR" && uv run $ACESTEP_ARGS || {
echo
echo "[Retry] Online dependency resolution failed, retrying in offline mode..."
echo
uv run --offline $ACESTEP_ARGS || {
echo
echo "========================================"
echo "[Error] Failed to start ACE-Step"
echo "========================================"
echo
echo "Both online and offline modes failed."
echo "Please check:"
echo " 1. Your internet connection (for first-time setup)"
echo " 2. If dependencies were previously installed (offline mode requires a prior successful install)"
echo " 3. Try running: uv sync --offline"
exit 1
}
}