feat: add --interactive flag to img_api_generate.sh
This commit is contained in:
@@ -40,6 +40,7 @@ DIM='\033[2m'
|
|||||||
|
|
||||||
CHECK_MARK="✓"
|
CHECK_MARK="✓"
|
||||||
CROSS_MARK="✗"
|
CROSS_MARK="✗"
|
||||||
|
QUESTION_MARK="?"
|
||||||
PALETTE="🎨"
|
PALETTE="🎨"
|
||||||
SPARKLES="✨"
|
SPARKLES="✨"
|
||||||
CAMERA="📸"
|
CAMERA="📸"
|
||||||
@@ -76,6 +77,7 @@ ASYNC_MODE=false
|
|||||||
DRY_RUN=false
|
DRY_RUN=false
|
||||||
VERBOSE=false
|
VERBOSE=false
|
||||||
UPSCALE=false
|
UPSCALE=false
|
||||||
|
INTERACTIVE=false
|
||||||
|
|
||||||
# Temp files for cleanup
|
# Temp files for cleanup
|
||||||
_TMP_FILES=()
|
_TMP_FILES=()
|
||||||
@@ -136,6 +138,22 @@ print_verbose() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prompt_confirm() {
|
||||||
|
local message="$1"
|
||||||
|
if [[ "$INTERACTIVE" == false ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -en "${BOLD_YELLOW}${QUESTION_MARK} ${message} [y/N] ${RESET}"
|
||||||
|
read -n 1 -r
|
||||||
|
echo ""
|
||||||
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||||
|
print_info "Operation cancelled by user."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# SPINNER
|
# SPINNER
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
@@ -551,6 +569,8 @@ generate_image() {
|
|||||||
[[ -n "$INPUT_IMAGE" ]] && print_field " " "Input Image" "$INPUT_IMAGE"
|
[[ -n "$INPUT_IMAGE" ]] && print_field " " "Input Image" "$INPUT_IMAGE"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
prompt_confirm "Proceed with image generation?" || return 1
|
||||||
|
|
||||||
local response
|
local response
|
||||||
if [[ "$ASYNC_MODE" == false ]]; then
|
if [[ "$ASYNC_MODE" == false ]]; then
|
||||||
# Synchronous mode - wait with spinner
|
# Synchronous mode - wait with spinner
|
||||||
@@ -687,6 +707,8 @@ download_result() {
|
|||||||
|
|
||||||
print_detail "Downloading result..."
|
print_detail "Downloading result..."
|
||||||
|
|
||||||
|
prompt_confirm "Download generated image?" || return 1
|
||||||
|
|
||||||
api_curl_binary GET "$url" "$_dl_output_path" || return 1
|
api_curl_binary GET "$url" "$_dl_output_path" || return 1
|
||||||
|
|
||||||
if [[ -f "$_dl_output_path" && -s "$_dl_output_path" ]]; then
|
if [[ -f "$_dl_output_path" && -s "$_dl_output_path" ]]; then
|
||||||
@@ -730,6 +752,8 @@ swap_face() {
|
|||||||
print_field "$CAMERA" "Target" "$target_image"
|
print_field "$CAMERA" "Target" "$target_image"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
prompt_confirm "Proceed with face swap?" || return 1
|
||||||
|
|
||||||
local options='{"processors":["face_swapper","face_enhancer"],"face_swapper":{"model":"hyperswap_1a_256"},"face_enhancer":{"model":"gfpgan_1.4","blend":80}}'
|
local options='{"processors":["face_swapper","face_enhancer"],"face_swapper":{"model":"hyperswap_1a_256"},"face_enhancer":{"model":"gfpgan_1.4","blend":80}}'
|
||||||
|
|
||||||
local tmp_resp
|
local tmp_resp
|
||||||
@@ -786,6 +810,8 @@ realesrgan_upscale() {
|
|||||||
print_field "$CAMERA" "Input" "$input_image"
|
print_field "$CAMERA" "Input" "$input_image"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
prompt_confirm "Proceed with image upscaling?" || return 1
|
||||||
|
|
||||||
local tmp_resp
|
local tmp_resp
|
||||||
tmp_resp=$(mktemp)
|
tmp_resp=$(mktemp)
|
||||||
_TMP_FILES+=("$tmp_resp")
|
_TMP_FILES+=("$tmp_resp")
|
||||||
@@ -851,6 +877,7 @@ OUTPUT:
|
|||||||
MODES:
|
MODES:
|
||||||
--async Use async mode with polling instead of sync
|
--async Use async mode with polling instead of sync
|
||||||
--dry-run Show curl commands without executing
|
--dry-run Show curl commands without executing
|
||||||
|
-i, --interactive Prompt before each API call
|
||||||
--verbose Verbose output
|
--verbose Verbose output
|
||||||
-h, --help Show this help message
|
-h, --help Show this help message
|
||||||
|
|
||||||
@@ -921,6 +948,10 @@ parse_args() {
|
|||||||
ASYNC_MODE=true
|
ASYNC_MODE=true
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-i|--interactive)
|
||||||
|
INTERACTIVE=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--dry-run)
|
--dry-run)
|
||||||
DRY_RUN=true
|
DRY_RUN=true
|
||||||
shift
|
shift
|
||||||
@@ -1058,10 +1089,12 @@ main() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
realesrgan_upscale "$final_input" upscale_path || exit 1
|
realesrgan_upscale "$final_input" upscale_path || true
|
||||||
|
|
||||||
# Use the upscaled image for summary/output
|
# Use the upscaled image for summary/output if it was created
|
||||||
output_path="$upscale_path"
|
if [[ -f "${upscale_path:-}" ]]; then
|
||||||
|
output_path="$upscale_path"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Summary
|
# Summary
|
||||||
|
|||||||
Reference in New Issue
Block a user