[CF]增加启动脚本

This commit is contained in:
edzhao 2025-06-04 11:50:39 +08:00
parent f32a53508b
commit 63a5d767f5
3 changed files with 125 additions and 0 deletions

35
start_app.bat Normal file
View File

@ -0,0 +1,35 @@
@echo off
chcp 65001 >nul
:: 简单启动脚本 - 激活虚拟环境并运行app.py (Windows版本)
echo 启动YOLO应用...
:: 检查虚拟环境是否存在
if not exist "venv" (
echo ❌ 错误: 虚拟环境不存在!
echo 请先运行 run_app.bat 来创建环境和安装依赖
pause
exit /b 1
)
:: 激活虚拟环境
echo 激活虚拟环境...
call venv\Scripts\activate.bat
:: 检查测试视频文件是否存在
if not exist "res\test.mp4" (
echo ❌ 错误: res\test.mp4 文件不存在!
echo 请在 res\ 目录中放置名为 test.mp4 的视频文件
pause
exit /b 1
)
echo ✅ 找到测试视频文件: res\test.mp4
:: 运行应用
echo 运行应用...
cd src
python app.py
echo ✅ 应用运行完成!
pause

58
start_app.py Executable file
View File

@ -0,0 +1,58 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import subprocess
def run_command(command, shell=False):
"""运行命令并返回结果"""
try:
result = subprocess.run(command, shell=shell, check=True,
capture_output=True, text=True)
return result.returncode, result.stdout, result.stderr
except subprocess.CalledProcessError as e:
return e.returncode, e.stdout, e.stderr
def main():
print("启动YOLO应用...")
# 检查虚拟环境是否存在
if not os.path.exists("venv"):
print("❌ 错误: 虚拟环境不存在!")
print("请先运行 python3 setup_and_run.py 来创建环境和安装依赖")
sys.exit(1)
# 确定虚拟环境中的Python解释器路径
if os.name == 'nt': # Windows
venv_python = os.path.join("venv", "Scripts", "python.exe")
else: # macOS/Linux
venv_python = os.path.join("venv", "bin", "python")
# 检查虚拟环境的Python是否存在
if not os.path.exists(venv_python):
print("❌ 错误: 虚拟环境损坏!")
print("请重新创建虚拟环境")
sys.exit(1)
# 检查测试视频文件是否存在
if not os.path.exists("res/test.mp4"):
print("❌ 错误: res/test.mp4 文件不存在!")
print("请在 res/ 目录中放置名为 test.mp4 的视频文件")
sys.exit(1)
print("✅ 找到测试视频文件: res/test.mp4")
# 运行应用
print("运行应用...")
os.chdir("src")
returncode, stdout, stderr = run_command([os.path.join("..", venv_python), "app.py"])
if returncode == 0:
print("✅ 应用运行完成!")
else:
print(f"❌ 应用运行失败: {stderr}")
sys.exit(1)
if __name__ == "__main__":
main()

32
start_app.sh Executable file
View File

@ -0,0 +1,32 @@
#!/bin/bash
# 简单启动脚本 - 激活虚拟环境并运行app.py
echo "启动YOLO应用..."
# 检查虚拟环境是否存在
if [ ! -d "venv" ]; then
echo "❌ 错误: 虚拟环境不存在!"
echo "请先运行 ./run_app.sh 来创建环境和安装依赖"
exit 1
fi
# 激活虚拟环境
echo "激活虚拟环境..."
source venv/bin/activate
# 检查测试视频文件是否存在
if [ ! -f "res/test.mp4" ]; then
echo "❌ 错误: res/test.mp4 文件不存在!"
echo "请在 res/ 目录中放置名为 test.mp4 的视频文件"
exit 1
fi
echo "✅ 找到测试视频文件: res/test.mp4"
# 运行应用
echo "运行应用..."
cd src
python app.py
echo "✅ 应用运行完成!"