Files
ai-shiliu/main.py
figmar 81115dc23d 初始提交:识流 AI 助手项目
微信自动回复机器人,基于截图+OCR识别消息,支持关键词规则和 AI(OpenAI/DeepSeek/Dify)自动回复。
技术栈:PySide6 + Flask + Vue3 + RapidOCR + SQLite

注:OCR大模型文件(.onnx / .pdiparams)不纳入版本控制,需单独下载。

🤖 Generated with [Qoder][https://qoder.com]
2026-05-30 15:09:40 +08:00

63 lines
1.7 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
import subprocess
import sys
from pathlib import Path
PROJECT_ROOT = Path(__file__).resolve().parent
VENV_ROOT = PROJECT_ROOT / ".venv"
VENV_DIR = VENV_ROOT / "Scripts"
VENV_PYTHON = VENV_DIR / "python.exe"
VENV_PYTHONW = VENV_DIR / "pythonw.exe"
def _resolve(path):
try:
return Path(path).resolve()
except Exception:
return None
def _running_in_project_venv():
current_prefix = _resolve(sys.prefix)
if current_prefix == _resolve(VENV_ROOT):
return True
current_executable = _resolve(sys.executable)
allowed_targets = {_resolve(VENV_PYTHON), _resolve(VENV_PYTHONW)}
return current_executable in allowed_targets
def _pick_reexec_python():
current_name = Path(sys.executable).name.lower()
if current_name == "pythonw.exe" and VENV_PYTHONW.exists():
return VENV_PYTHONW
if VENV_PYTHON.exists():
return VENV_PYTHON
if VENV_PYTHONW.exists():
return VENV_PYTHONW
raise RuntimeError(f"未找到项目 .venv 解释器: {VENV_PYTHON}")
def ensure_project_venv():
if _running_in_project_venv():
return
if os.environ.get("OPENCLAW_PROJECT_VENV_REEXEC") == "1":
raise RuntimeError("重启后仍未进入项目 .venv请检查 .venv 是否损坏或系统 Python 安装是否异常")
env = os.environ.copy()
env["OPENCLAW_PROJECT_VENV_REEXEC"] = "1"
target_python = _pick_reexec_python()
subprocess.Popen([str(target_python), str(PROJECT_ROOT / "main.py")], cwd=str(PROJECT_ROOT), env=env)
raise SystemExit(0)
ensure_project_venv()
from PySide6.QtWidgets import QApplication
from app.presentation.main_window import MainWindow
if __name__ == "__main__":
app = QApplication(sys.argv)
w = MainWindow()
sys.exit(app.exec())