run.sh 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/bash
  2. # 内容识别脚本启动脚本
  3. echo "内容识别脚本启动中..."
  4. # 检查Python环境
  5. if ! command -v python3 &> /dev/null; then
  6. echo "错误: 未找到 python3 命令"
  7. exit 1
  8. fi
  9. # 检查依赖
  10. echo "检查依赖..."
  11. python3 -c "import pymysql, google.genai, requests, dotenv" 2>/dev/null
  12. if [ $? -ne 0 ]; then
  13. echo "错误: 缺少必要的依赖包,请先安装: pip install -r requirements.txt"
  14. exit 1
  15. fi
  16. # 检查环境变量文件
  17. if [ ! -f ".env" ]; then
  18. echo "警告: 未找到 .env 文件,将使用默认配置"
  19. echo "建议创建 .env 文件并配置必要的环境变量"
  20. fi
  21. # 显示帮助信息
  22. echo ""
  23. echo "使用方法:"
  24. echo " python3 indentify.py --single # 处理单条记录"
  25. echo " python3 indentify.py --batch 20 # 批量处理20条记录"
  26. echo " python3 indentify.py --continuous # 连续处理模式(无限制)"
  27. echo " python3 indentify.py --continuous --max-records 100 # 连续处理最多100条"
  28. echo " python3 indentify.py --continuous --delay 5 # 连续处理,间隔5秒"
  29. echo " python3 indentify.py --help # 显示帮助信息"
  30. echo ""
  31. # 运行测试(可选)
  32. read -p "是否先运行测试?(y/N): " -n 1 -r
  33. echo
  34. if [[ $REPLY =~ ^[Yy]$ ]]; then
  35. echo "运行测试..."
  36. python3 test_identify.py
  37. echo ""
  38. fi
  39. # 询问运行模式
  40. echo "请选择运行模式:"
  41. echo "1) 处理单条记录"
  42. echo "2) 批量处理记录"
  43. echo "3) 连续处理模式(推荐)"
  44. echo "4) 退出"
  45. read -p "请输入选择 (1-4): " choice
  46. case $choice in
  47. 1)
  48. echo "启动单条记录处理模式..."
  49. python3 indentify.py --single
  50. ;;
  51. 2)
  52. read -p "请输入批量处理数量 (默认10): " batch_size
  53. batch_size=${batch_size:-10}
  54. echo "启动批量处理模式,处理 $batch_size 条记录..."
  55. python3 indentify.py --batch $batch_size
  56. ;;
  57. 3)
  58. echo "启动连续处理模式..."
  59. echo "此模式将自动处理数据库中的所有记录,一条完成后自动处理下一条"
  60. echo ""
  61. read -p "是否设置最大处理数量限制?(y/N): " -n 1 -r
  62. echo
  63. if [[ $REPLY =~ ^[Yy]$ ]]; then
  64. read -p "请输入最大处理数量: " max_records
  65. read -p "请输入处理间隔时间(秒,默认2): " delay
  66. delay=${delay:-2}
  67. echo "启动连续处理模式,最多处理 $max_records 条记录,间隔 $delay 秒..."
  68. python3 indentify.py --continuous --max-records $max_records --delay $delay
  69. else
  70. read -p "请输入处理间隔时间(秒,默认2): " delay
  71. delay=${delay:-2}
  72. echo "启动连续处理模式,无数量限制,间隔 $delay 秒..."
  73. python3 indentify.py --continuous --delay $delay
  74. fi
  75. ;;
  76. 4)
  77. echo "退出"
  78. exit 0
  79. ;;
  80. *)
  81. echo "无效选择,退出"
  82. exit 1
  83. ;;
  84. esac