feat: 新增代码

This commit is contained in:
Daniel
2026-04-07 00:37:39 +08:00
commit 8d0b729f2f
29 changed files with 1768 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
$ErrorActionPreference = "Stop"
$Root = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
Set-Location $Root
if (!(Get-Command py -ErrorAction SilentlyContinue) -and !(Get-Command python -ErrorAction SilentlyContinue)) {
throw "Python launcher (py) or python not found"
}
if (Test-Path .venv) {
Write-Host ".venv already exists, reusing"
} else {
if (Get-Command py -ErrorAction SilentlyContinue) {
py -3 -m venv .venv
} else {
python -m venv .venv
}
}
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
pip install -r requirements.txt
if (!(Get-Command ffmpeg -ErrorAction SilentlyContinue)) {
Write-Warning "ffmpeg not found in PATH. Please install ffmpeg and ensure PATH is updated."
}
New-Item -ItemType Directory -Force outputs, runtime, runtime\logs, models\ltx, models\hunyuan | Out-Null
if (!(Test-Path .env)) { Copy-Item .env.example .env }
Write-Host "[OK] install completed"
Write-Host "next: .\\scripts\\run_server.ps1"

View File

@@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT_DIR"
if ! command -v python3 >/dev/null 2>&1; then
echo "[ERROR] python3 not found"
exit 1
fi
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
pip install -r requirements.txt
if command -v apt-get >/dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y ffmpeg
else
echo "[WARN] apt-get unavailable, please install ffmpeg manually"
fi
mkdir -p outputs runtime runtime/logs models/ltx models/hunyuan
if [ ! -f .env ]; then
cp .env.example .env
fi
echo "[OK] install completed"
echo "next: source .venv/bin/activate && bash scripts/run_server.sh"

View File

@@ -0,0 +1,10 @@
from app.settings import settings
from app.task_store import TaskStore
if __name__ == "__main__":
store = TaskStore(settings.sqlite_path)
store.migrate()
print("DB migrated:", settings.sqlite_path)
for row in store.list_migrations():
print(row)

View File

@@ -0,0 +1,18 @@
@echo off
setlocal
cd /d %~dp0\..
if not exist .venv (
echo [ERROR] .venv not found, run scripts\install_windows_env.ps1 first
exit /b 1
)
if not exist .env (
echo [ERROR] .env not found, copy from .env.example
exit /b 1
)
call .venv\Scripts\activate.bat
for /f "usebackq tokens=1,* delims==" %%A in (".env") do (
if not "%%A"=="" set "%%A=%%B"
)
if "%APP_HOST%"=="" set APP_HOST=0.0.0.0
if "%APP_PORT%"=="" set APP_PORT=8000
python -m uvicorn app.main:app --host %APP_HOST% --port %APP_PORT%

View File

@@ -0,0 +1,20 @@
$ErrorActionPreference = "Stop"
$Root = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
Set-Location $Root
if (!(Test-Path .venv)) { throw ".venv not found, run scripts/install_windows_env.ps1 first" }
if (!(Test-Path .env)) { throw ".env not found, copy from .env.example" }
.\.venv\Scripts\Activate.ps1
Get-Content .env | ForEach-Object {
if ($_ -match "^\s*#") { return }
if ($_ -match "^\s*$") { return }
$parts = $_ -split "=", 2
if ($parts.Length -eq 2) {
[System.Environment]::SetEnvironmentVariable($parts[0], $parts[1], "Process")
}
}
$hostValue = if ($env:APP_HOST) { $env:APP_HOST } else { "0.0.0.0" }
$portValue = if ($env:APP_PORT) { $env:APP_PORT } else { "8000" }
python -m uvicorn app.main:app --host $hostValue --port $portValue

View File

@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT_DIR"
if [ ! -d .venv ]; then
echo "[ERROR] .venv not found, run scripts/install_wsl_env.sh first"
exit 1
fi
if [ ! -f .env ]; then
echo "[ERROR] .env not found, copy from .env.example"
exit 1
fi
source .venv/bin/activate
set -a
source .env
set +a
python -m uvicorn app.main:app --host "${APP_HOST:-0.0.0.0}" --port "${APP_PORT:-8000}"

View File

@@ -0,0 +1,48 @@
import json
import sys
import time
import requests
BASE_URL = sys.argv[1] if len(sys.argv) > 1 else "http://127.0.0.1:8000"
def main() -> None:
health = requests.get(f"{BASE_URL}/health", timeout=15)
health.raise_for_status()
print("[health]", json.dumps(health.json(), ensure_ascii=False))
payload = {
"prompt": "a lonely man walking in a rainy neon street, cinematic, handheld camera",
"negative_prompt": "blurry, deformed face, extra limbs, flicker",
"quality_mode": "preview",
"duration_sec": 1,
"width": 320,
"height": 240,
"fps": 8,
"steps": 8,
"seed": 123456,
}
created = requests.post(f"{BASE_URL}/generate", json=payload, timeout=30)
created.raise_for_status()
created_data = created.json()
task_id = created_data["task_id"]
print("[create]", json.dumps(created_data, ensure_ascii=False))
while True:
status = requests.get(f"{BASE_URL}/tasks/{task_id}", timeout=15)
status.raise_for_status()
status_data = status.json()
print("[status]", json.dumps(status_data, ensure_ascii=False))
if status_data["status"] in {"SUCCEEDED", "FAILED"}:
break
time.sleep(2)
result = requests.get(f"{BASE_URL}/tasks/{task_id}/result", timeout=15)
result.raise_for_status()
print("[result]", json.dumps(result.json(), ensure_ascii=False, indent=2))
if __name__ == "__main__":
main()