Files
human-voice-rewrite-demo/local_start.sh
T

57 lines
1.9 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# Human Voice Rewrite Demo 一键启动
# Key 读取顺序:
# 1) $HVR_BACKEND_ENV 显式指定
# 2) 仓库环境 ../../prodream_backend/.env(本仓库开发时)
# 3) 本目录 .env(独立分发包:内置 Key 与代理地址)
# 首次运行自动创建独立 .venv 并安装依赖
# 用法: ./local_start.sh (端口可用 HVR_PORT 覆盖,默认 8000
set -euo pipefail
cd "$(dirname "$0")"
if [ ! -d .venv ]; then
echo "首次运行:创建独立虚拟环境并安装依赖…"
python3 -m venv .venv
.venv/bin/pip install -q --upgrade pip
.venv/bin/pip install -q -r requirements.txt
fi
BACKEND_ENV="${HVR_BACKEND_ENV:-}"
if [ -z "$BACKEND_ENV" ]; then
if [ -f "../../prodream_backend/.env" ]; then
BACKEND_ENV="../../prodream_backend/.env"
elif [ -f ".env" ]; then
BACKEND_ENV=".env"
fi
fi
if [ -z "$BACKEND_ENV" ] || [ ! -f "$BACKEND_ENV" ]; then
echo "错误:找不到环境变量文件。可用 HVR_BACKEND_ENV 指定,或在本目录放置 .env" >&2
exit 1
fi
# 只提取需要的 key,绝不 source 整个 .envdotenv 格式不是 bash 语法,直接执行会出错)
pick() { # pick KEY <file> -> 值(去首尾引号)
local line value
line="$(grep -E "^$1=" "$2" 2>/dev/null | head -1 || true)"
value="${line#*=}"
case "$value" in
\"*\") value="${value#\"}"; value="${value%\"}" ;;
\'*\') value="${value#\'}"; value="${value%\'}" ;;
esac
printf '%s' "$value"
}
API_KEY="$(pick PRODREAM_BACKEND_OPENROUTER_API_KEY "$BACKEND_ENV")"
PROXY_URL="$(pick PRODREAM_BACKEND_OPENROUTER_PROXY_URL "$BACKEND_ENV")"
if [ -z "$API_KEY" ]; then
echo "错误:$BACKEND_ENV 中没有配置 PRODREAM_BACKEND_OPENROUTER_API_KEY" >&2
exit 1
fi
export OPENROUTER_API_KEY="$API_KEY"
export OPENROUTER_PROXY_URL="$PROXY_URL"
PORT="${HVR_PORT:-8000}"
echo "Human Voice Rewrite Demo: http://127.0.0.1:${PORT}"
exec .venv/bin/uvicorn main:app --host 127.0.0.1 --port "$PORT"