-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.ps1
More file actions
117 lines (102 loc) · 3.85 KB
/
Copy pathstart.ps1
File metadata and controls
117 lines (102 loc) · 3.85 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
# 银发族智能旅行助手启动脚本 (PowerShell版)
# 推荐使用此脚本,支持UTF-8编码
Write-Host ""
Write-Host "==============================================" -ForegroundColor Cyan
Write-Host "🧳 银发族智能旅行助手启动脚本 (PowerShell版)" -ForegroundColor Green
Write-Host "==============================================" -ForegroundColor Cyan
Write-Host ""
# 检查Python是否安装
try {
$pythonVersion = python --version 2>$null
Write-Host "✅ $pythonVersion" -ForegroundColor Green
} catch {
Write-Host "❌ 错误:未找到Python,请先安装Python 3.8+" -ForegroundColor Red
Write-Host "请访问:https://www.python.org/downloads/ 下载安装" -ForegroundColor Yellow
Read-Host "按回车键退出"
exit 1
}
# 检查pip是否可用
try {
$pipVersion = pip --version 2>$null
Write-Host "✅ pip已安装" -ForegroundColor Green
} catch {
Write-Host "❌ 错误:未找到pip,请检查Python安装" -ForegroundColor Red
Read-Host "按回车键退出"
exit 1
}
# 检查.env文件
if (-not (Test-Path ".env")) {
Write-Host ""
Write-Host "⚠️ 警告:未找到.env文件" -ForegroundColor Yellow
Write-Host "请复制.env.example为.env,并填入您的ModelScope Token" -ForegroundColor Yellow
Write-Host ""
if (Test-Path ".env.example") {
Copy-Item ".env.example" ".env" -Force
Write-Host "✅ 已创建.env文件,请编辑并填入您的ModelScope Token" -ForegroundColor Green
Write-Host ""
}
Write-Host "请编辑.env文件后重新运行此脚本" -ForegroundColor Yellow
Write-Host "例如:MODELSCOPE_TOKEN=你的token值" -ForegroundColor Yellow
Write-Host ""
Read-Host "按回车键退出"
exit 1
}
Write-Host "✅ .env文件检查通过" -ForegroundColor Green
Write-Host ""
# 检查虚拟环境
if (-not (Test-Path "venv")) {
Write-Host "📦 创建虚拟环境..." -ForegroundColor Cyan
python -m venv venv
if ($LASTEXITCODE -ne 0) {
Write-Host "❌ 虚拟环境创建失败" -ForegroundColor Red
Read-Host "按回车键退出"
exit 1
}
Write-Host "✅ 虚拟环境创建成功" -ForegroundColor Green
Write-Host ""
} else {
Write-Host "✅ 虚拟环境已存在" -ForegroundColor Green
}
Write-Host "📦 安装依赖包..." -ForegroundColor Cyan
& "venv\Scripts\Activate.ps1"
pip install -r requirements.txt
if ($LASTEXITCODE -ne 0) {
Write-Host "❌ 依赖包安装失败" -ForegroundColor Red
Read-Host "按回车键退出"
exit 1
}
Write-Host "✅ 依赖包安装完成" -ForegroundColor Green
Write-Host ""
Write-Host "📋 加载环境变量..." -ForegroundColor Cyan
# 加载.env文件中的环境变量
if (Test-Path ".env") {
Get-Content ".env" | ForEach-Object {
$line = $_.Trim()
if ($line -and -not $line.StartsWith("#")) {
$key, $value = $line -split "=", 2
if ($key -and $value) {
# 移除引号
$value = $value.Trim('"', "'")
[Environment]::SetEnvironmentVariable($key.Trim(), $value.Trim(), "Process")
}
}
}
Write-Host "✅ 环境变量加载完成" -ForegroundColor Green
} else {
Write-Host "⚠️ 未找到.env文件" -ForegroundColor Yellow
}
Write-Host ""
Write-Host "🚀 启动应用..." -ForegroundColor Cyan
Write-Host "==============================================" -ForegroundColor Cyan
Write-Host "访问地址:http://localhost:7860" -ForegroundColor Green
Write-Host "==============================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "按 Ctrl+C 停止应用" -ForegroundColor Yellow
Write-Host ""
python travel_assistant_improved.py
# 如果程序异常退出
if ($LASTEXITCODE -ne 0) {
Write-Host ""
Write-Host "程序异常退出" -ForegroundColor Red
Read-Host "按任意键继续"
}