Spaces:
Sleeping
Sleeping
eithney
Refactor application to Flask: enhance structure with RESTful API, static file support, and logging. Update Dockerfile for production with Gunicorn and health checks. Expand requirements for Flask and OpenSearch integration.
b0a1454 | # Flask 应用启动脚本 | |
| # 设置颜色输出 | |
| GREEN='\033[0;32m' | |
| BLUE='\033[0;34m' | |
| RED='\033[0;31m' | |
| NC='\033[0m' # No Color | |
| echo -e "${BLUE}================================${NC}" | |
| echo -e "${BLUE}Flask 应用启动脚本${NC}" | |
| echo -e "${BLUE}================================${NC}" | |
| # 检查 Python 版本 | |
| echo -e "${GREEN}检查 Python 版本...${NC}" | |
| python3.12 --version || python3 --version | |
| # 检查虚拟环境 | |
| if [ -d "venv" ]; then | |
| echo -e "${GREEN}激活虚拟环境...${NC}" | |
| source venv/bin/activate | |
| else | |
| echo -e "${BLUE}虚拟环境不存在,是否创建? (y/n)${NC}" | |
| read -r response | |
| if [[ "$response" == "y" ]]; then | |
| echo -e "${GREEN}创建虚拟环境...${NC}" | |
| python3 -m venv venv | |
| source venv/bin/activate | |
| fi | |
| fi | |
| # 安装依赖 | |
| echo -e "${GREEN}检查依赖...${NC}" | |
| if [ -f "requirements.txt" ]; then | |
| pip install -r requirements.txt | |
| else | |
| echo -e "${RED}requirements.txt 不存在${NC}" | |
| exit 1 | |
| fi | |
| # 加载环境变量 | |
| if [ -f ".env" ]; then | |
| echo -e "${GREEN}加载环境变量...${NC}" | |
| export $(cat .env | grep -v '^#' | xargs) | |
| else | |
| echo -e "${BLUE}.env 文件不存在,使用默认配置${NC}" | |
| fi | |
| # 启动应用 | |
| echo -e "${GREEN}启动 Flask 应用...${NC}" | |
| python3.12 app.py || python3 app.py | |
| # 如果需要使用 Gunicorn(生产环境) | |
| # gunicorn -w 4 -b 0.0.0.0:7860 --timeout 120 --access-logfile - --error-logfile - app:app | |