初始提交:识流 AI 助手项目
微信自动回复机器人,基于截图+OCR识别消息,支持关键词规则和 AI(OpenAI/DeepSeek/Dify)自动回复。 技术栈:PySide6 + Flask + Vue3 + RapidOCR + SQLite 注:OCR大模型文件(.onnx / .pdiparams)不纳入版本控制,需单独下载。 🤖 Generated with [Qoder][https://qoder.com]
This commit is contained in:
46
backend_main.py
Normal file
46
backend_main.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from app.application.services import AppConfig
|
||||
from app.infrastructure.backend import start_backend
|
||||
|
||||
PROJECT_ROOT = Path(__file__).resolve().parent
|
||||
VENV_ROOT = PROJECT_ROOT / ".venv"
|
||||
VENV_DIR = VENV_ROOT / "Scripts"
|
||||
VENV_PYTHON = VENV_DIR / "python.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)
|
||||
return current_executable == _resolve(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 是否损坏")
|
||||
if not VENV_PYTHON.exists():
|
||||
raise RuntimeError(f"未找到项目 .venv 解释器: {VENV_PYTHON}")
|
||||
os.environ["OPENCLAW_PROJECT_VENV_REEXEC"] = "1"
|
||||
os.chdir(str(PROJECT_ROOT))
|
||||
os.execv(str(VENV_PYTHON), [str(VENV_PYTHON), str(PROJECT_ROOT / "backend_main.py")])
|
||||
|
||||
|
||||
ensure_project_venv()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
config = AppConfig()
|
||||
start_backend(host=config.host, port=config.port)
|
||||
Reference in New Issue
Block a user